Beispiel #1
0
    function AA_results_High($round, $layout, $singleRound)
    {
        $zaehler = 0;
        $max = 0;
        foreach ($_POST as $key => $val) {
            $arr_key = explode('_', $key);
            if ($arr_key[0] == 'hight') {
                $max = $arr_key[1];
            }
        }
        if ($max > 0) {
            $max++;
        } else {
            $max = $GLOBALS['cfgCountHeight'];
        }
        require './lib/cl_gui_button.lib.php';
        require './config.inc.php';
        require './lib/common.lib.php';
        require './lib/heats.lib.php';
        require './lib/results.lib.php';
        require './lib/utils.lib.php';
        require './lib/cl_performance.lib.php';
        $presets = AA_results_getPresets($round);
        // read GET/POST variables
        $performance = 0;
        // initialize
        $svm = AA_checkSVM(0, $round);
        // decide whether to show club or team name
        $prog_mode = AA_results_getProgramMode();
        if ($singleRound > 0) {
            $single_svm = AA_checkSVM(0, $singleRound);
            // decide whether to show club or team name
        }
        $click = true;
        // true = User clicks at this athlete      false = user save athlete before
        //
        // update result(s)
        //
        if ($_POST['arg'] == 'save_res') {
            $click = false;
            // check if athlet valid
            if (AA_checkReference("serienstart", "xSerienstart", $_POST['start']) == 0) {
                AA_printErrorMsg($strErrAthleteNotInHeat);
            } else {
                AA_utils_changeRoundStatus($round, $cfgRoundStatus['results_in_progress']);
                if (!empty($GLOBALS['AA_ERROR'])) {
                    AA_printErrorMsg($GLOBALS['AA_ERROR']);
                }
                mysql_query("\r\n            LOCK TABLES\r\n                disziplin READ\r\n                , runde READ\r\n                , runde AS r READ \r\n                , serienstart WRITE\r\n                , wettkampf READ\r\n                , wettkampf AS w READ \r\n                , resultat WRITE\r\n                , wertungstabelle READ\r\n                , wertungstabelle_punkte READ\r\n                , meeting READ\r\n        ");
                // validate result
                if ($_POST['attempts'] < 0) {
                    $perf = new PerformanceAttempt($_POST['attempts']);
                    $performance = $perf->getPerformance();
                } else {
                    $perf = new PerformanceAttempt($_POST['perf']);
                    $performance = $perf->getPerformance();
                }
                // validate attempts
                if ($performance > 0) {
                    $info = strtoupper($_POST['attempts']);
                    $info = strtr($info, '0', 'O');
                    $info = str_replace("OOO", "O", $info);
                    $info = str_replace("OO", "O", $info);
                    if (in_array($info, $cfgResultsHigh) == false) {
                        $info = NULL;
                    }
                } else {
                    // negative or zero result
                    $info = $cfgResultsHighOut;
                }
                // check on failed attempts (not more than 3 X in a row, it doesent matter on which hights)
                $res = mysql_query("SELECT Leistung, Info FROM \r\n                    resultat\r\n                WHERE\r\n                    xSerienstart = " . $_POST['start'] . "\r\n                ORDER BY\r\n                    Leistung ASC");
                $Xcount = 0;
                while ($row = mysql_fetch_array($res)) {
                    if (strpos($row[1], strtoupper("o")) === false) {
                        preg_match_all("[X]", $row[1], $m);
                        $Xcount += count($m[0]);
                    } else {
                        $Xcount = 0;
                    }
                }
                if (strpos($info, strtoupper("o")) === false) {
                    // count X for last entered attempt
                    preg_match_all("[X]", $info, $m);
                    $Xcount += count($m[0]);
                } else {
                    $Xcount = 0;
                }
                if ($info == $cfgResultsHighOut || $Xcount >= 3) {
                    // last attempt
                    if ($cfgProgramMode[$prog_mode]['name'] == $strProgramModeBackoffice) {
                        $_POST['athlete'] = $_POST['athlete'] + 1;
                        // next athlete
                    }
                    $points = 0;
                } else {
                    /*$sql_sex = "SELECT Geschlecht 
                           FROM athlet 
                      LEFT JOIN anmeldung USING(xAthlet) 
                      LEFT JOIN start USING(xAnmeldung) 
                      LEFT JOIN serienstart USING(xStart) 
                          WHERE xSerienstart = ".$_POST['start'].";";*/
                    $sql_sex = "SELECT Geschlecht \r\n                          FROM kategorie \r\n                     LEFT JOIN wettkampf USING(xKategorie) \r\n                     LEFT JOIN start USING(xWettkampf) \r\n                     LEFT JOIN serienstart USING(xStart) \r\n                         WHERE xSerienstart = " . $_POST['start'] . ";";
                    $query_sex = mysql_query($sql_sex);
                    if ($_POST['attempts'] == '-') {
                        $points = 0;
                    } else {
                        if ($single_svm) {
                            $single_presets = AA_results_getPresets($singleRound);
                            // read GET/POST variables
                            $points = AA_utils_calcPoints($single_presets['event'], $performance, 0, mysql_result($query_sex, 0, 'Geschlecht'));
                        } else {
                            $points = AA_utils_calcPoints($presets['event'], $performance, 0, mysql_result($query_sex, 0, 'Geschlecht'));
                        }
                    }
                }
                if (!empty($info)) {
                    AA_results_update($performance, $info, $points);
                } else {
                    $_POST['athlete']--;
                }
            }
            // ET Athlete valid
            mysql_query("UNLOCK TABLES");
            // set ranks after every new result in mode = decentral with ranking
            // ******************************************************************
            if ($prog_mode == 2) {
                $eval = AA_results_getEvaluationType($round);
                $combined = AA_checkCombined(0, $round);
                mysql_query("DROP TABLE IF EXISTS tempresult");
                // temporary table
                if (mysql_errno() > 0) {
                    // DB error
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    mysql_query("\r\n                LOCK TABLES\r\n                    serie READ\r\n                    , wettkampf READ\r\n                    , resultat WRITE\r\n                    , serienstart WRITE\r\n                    , tempresult WRITE\r\n            ");
                    // clean ranks, set all to 0
                    mysql_query("UPDATE \r\n                    serienstart\r\n                    , serie\r\n                SET\r\n                    serienstart.Rang = 0\r\n                WHERE\r\n                    serienstart.xSerie = serie.xSerie\r\n                AND    serie.xRunde = {$round}");
                    // Set up a temporary table to hold all results for ranking.
                    mysql_query("\r\n                CREATE TABLE tempresult (\r\n                    xSerienstart int(11)\r\n                    , xSerie int(11)\r\n                    , Leistung int(9)\r\n                    , TopX int(1)\r\n                    , TotalX int(2)\r\n                    )\r\n                    TYPE=HEAP \r\n            ");
                    if (mysql_errno() > 0) {
                        // DB error
                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                    } else {
                        // if this is a combined event, rank all rounds togheter
                        $roundSQL = "";
                        if ($combined) {
                            $roundSQL = "AND serie.xRunde IN (";
                            $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $presets['event']);
                            while ($row_c = mysql_fetch_array($res_c)) {
                                $roundSQL .= $row_c[0] . ",";
                            }
                            $roundSQL = substr($roundSQL, 0, -1) . ")";
                        } else {
                            $roundSQL = "AND serie.xRunde = {$round}";
                        }
                        // read all valid results (per athlet)
                        $result = mysql_query("\r\n                    SELECT\r\n                        resultat.Leistung\r\n                        , resultat.Info\r\n                        , serienstart.xSerienstart\r\n                        , serienstart.xSerie\r\n                    FROM\r\n                        resultat\r\n                        , serienstart\r\n                        , serie\r\n                    WHERE resultat.xSerienstart = serienstart.xSerienstart\r\n                    AND serienstart.xSerie = serie.xSerie\r\n                    {$roundSQL}\r\n                    AND resultat.Leistung != 0\r\n                    ORDER BY\r\n                        serienstart.xSerienstart\r\n                        ,resultat.Leistung DESC\r\n                ");
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $leistung = 0;
                            $serienstart = 0;
                            $serie = 0;
                            $topX = 0;
                            $totX = 0;
                            $ss = 0;
                            // athlete's ID
                            $tt = FALSE;
                            // top result check
                            // process every result
                            while ($row = mysql_fetch_row($result)) {
                                // new athlete: save last athlete's data
                                if ($ss != $row[2] && $ss != 0) {
                                    if ($leistung != 0) {
                                        // add one row per athlete to temp table
                                        mysql_query("\r\n                                    INSERT INTO tempresult\r\n                                    VALUES(\r\n                                        {$serienstart}\r\n                                        , {$serie}\r\n                                        , {$leistung}\r\n                                        , {$topX}\r\n                                        , {$totX})\r\n                                ");
                                        if (mysql_errno() > 0) {
                                            // DB error
                                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                        }
                                    }
                                    // initialize variables
                                    $leistung = 0;
                                    $serienstart = 0;
                                    $serie = 0;
                                    $totX = 0;
                                    $topX = 0;
                                    $tt = FALSE;
                                }
                                // save data of current athlete's top result
                                if ($tt == FALSE && strstr($row[1], 'O')) {
                                    $leistung = $row[0];
                                    $serienstart = $row[2];
                                    $serie = $row[3];
                                    $topX = substr_count($row[1], 'X');
                                    $tt = TRUE;
                                }
                                // count total invalid attempts
                                $totX = $totX + substr_count($row[1], 'X');
                                $ss = $row[2];
                                // keep athlete's ID
                            }
                            mysql_free_result($result);
                            // insert last pending data in temp table
                            if ($ss != 0 && $leistung != 0) {
                                mysql_query("\r\n                            INSERT INTO tempresult\r\n                            VALUES(\r\n                                {$serienstart}\r\n                                , {$serie}\r\n                                , {$leistung}\r\n                                , {$topX}\r\n                                , {$totX})\r\n                        ");
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                        }
                        if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                            // eval per heat
                            $order = "xSerie ,";
                        } else {
                            // default: rank results from all heats together
                            $order = "";
                        }
                        // Read rows from temporary table ordered by performance,
                        // nbr of invalid attempts for top performance and
                        // total nbr of invalid attempts to determine ranking.
                        $result = mysql_query("\r\n                    SELECT\r\n                        xSerienstart\r\n                        , xSerie\r\n                        , Leistung\r\n                        , TopX\r\n                        , TotalX\r\n                    FROM\r\n                        tempresult\r\n                    ORDER BY\r\n                        {$order}\r\n                        Leistung DESC\r\n                        ,TopX ASC\r\n                        ,TotalX ASC\r\n                ");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $heat = 0;
                            $perf = 0;
                            $topX = 0;
                            $totalX = 0;
                            $i = 0;
                            $rank = 0;
                            // set rank for every athlete
                            while ($row = mysql_fetch_row($result)) {
                                if ($eval == $cfgEvalType[$strEvalTypeHeat] && $heat != $row[1]) {
                                    $i = 0;
                                    // restart ranking
                                    $perf = 0;
                                    $topX = 0;
                                    $totalX = 0;
                                }
                                $j++;
                                // increment ranking
                                if ($perf != $row[2] || $topX != $row[3] || $totalX != $row[4]) {
                                    $rank = $j;
                                    // next rank (only if not same performance)
                                }
                                mysql_query("\r\n                            UPDATE serienstart SET\r\n                                Rang = {$rank}\r\n                            WHERE xSerienstart = {$row['0']}\r\n                        ");
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                                $heat = $row[1];
                                // keep current heat ID
                                $perf = $row[2];
                                $topX = $row[3];
                                $totalX = $row[4];
                            }
                            mysql_free_result($result);
                        }
                        mysql_query("DROP TABLE IF EXISTS tempresult");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                    }
                    // ET DB error (create temp table)
                    mysql_query("UNLOCK TABLES");
                }
                // ET DB error (drop temp table)
                AA_results_setNotStarted($round);
                // update athletes with no result
                if (!empty($GLOBALS['AA_ERROR'])) {
                    AA_printErrorMsg($GLOBALS['AA_ERROR']);
                }
            }
            // end prog mode = 2 (decentral with ranking)
        } elseif ($_POST['arg'] == 'save_height') {
            $max = $_POST['max'];
            $arr_prev = array();
            $arr_new = array();
            for ($g = 0; $g < $max; $g++) {
                $name = "hight_" . $g;
                $hiddenName = "hiddenHeight_" . $g;
                $previous_height = $_POST[$hiddenName];
                $previous_height = new PerformanceAttempt($previous_height);
                $previous_height = $previous_height->getPerformance();
                if (isset($_POST[$name])) {
                    $new_height = $_POST[$name];
                    $new_height = new PerformanceAttempt($new_height);
                    $new_height = $new_height->getPerformance();
                } else {
                    $new_height = $previous_height;
                }
                $arr_prev[$g] = $previous_height;
                $arr_new[$g] = $new_height;
            }
            $diff = 0;
            $first_change = false;
            foreach ($arr_prev as $key => $val) {
                if ($first_change) {
                    $arr_new[$key] = $arr_new[$key - 1] + $diff;
                } else {
                    if ($val == $arr_new[$key]) {
                        if ($diff > 0) {
                            $arr_new[$key] = $arr_new[$key - 1] + $diff;
                        }
                    } else {
                        if ($diff == 0) {
                            if ($key == 0) {
                                $first_change = true;
                                if ($_POST['disCode'] == '310') {
                                    // jump
                                    $diff = $cfgHeightDiffJump * 100;
                                } elseif ($_POST['disCode'] == '320') {
                                    $diff = $cfgHeightDiffPole * 100;
                                    // pole
                                } else {
                                    $diff = $cfgHeightDiffJump * 100;
                                }
                            } else {
                                $diff = $arr_new[$key] - $keep_val;
                            }
                        } else {
                            $arr_new[$key] = $arr_prev[$key] + $diff;
                        }
                    }
                }
                $keep_val = $val;
            }
            AA_delHeight($_POST['round'], $_POST['heat']);
            AA_setHeight($arr_new, $_POST['round'], $_POST['heat']);
            $name = "hight_" . $max;
            if (isset($_POST[$name]) && !empty($_POST[$name])) {
                $new_height = $_POST[$name];
                $new_height = new PerformanceAttempt($new_height);
                $new_height = $new_height->getPerformance();
                // insert new hight
                $sql = "INSERT INTO hoehe SET \r\n                                    hoehe = " . $new_height . ",\r\n                                    xRunde = " . $_POST['round'] . ",   \r\n                                    xSerie = " . $_POST['heat'];
                $res = mysql_query($sql);
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                }
            }
        } else {
            if ($_GET['arg'] == 'delete') {
                AA_results_delete($round, $_GET['item']);
            }
        }
        //
        // terminate result processing
        //
        if ($_GET['arg'] == 'results_done') {
            $eval = AA_results_getEvaluationType($round);
            $combined = AA_checkCombined(0, $round);
            mysql_query("DROP TABLE IF EXISTS tempresult");
            // temporary table
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                mysql_query("\r\n            LOCK TABLES\r\n                serie READ\r\n                , wettkampf READ\r\n                , resultat WRITE\r\n                , serienstart WRITE\r\n                , tempresult WRITE\r\n        ");
                // clean ranks, set all to 0
                mysql_query("UPDATE \r\n                serienstart\r\n                , serie\r\n            SET\r\n                serienstart.Rang = 0\r\n            WHERE\r\n                serienstart.xSerie = serie.xSerie\r\n            AND    serie.xRunde = {$round}");
                // Set up a temporary table to hold all results for ranking.
                mysql_query("\r\n            CREATE TABLE tempresult (\r\n                xSerienstart int(11)\r\n                , xSerie int(11)\r\n                , Leistung int(9)\r\n                , TopX int(1)\r\n                , TotalX int(2)\r\n                )\r\n               TYPE=HEAP\r\n        ");
                if (mysql_errno() > 0) {
                    // DB error
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    // if this is a combined event, rank all rounds togheter
                    $roundSQL = "";
                    if ($combined) {
                        $roundSQL = "AND serie.xRunde IN (";
                        $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $presets['event']);
                        while ($row_c = mysql_fetch_array($res_c)) {
                            $roundSQL .= $row_c[0] . ",";
                        }
                        $roundSQL = substr($roundSQL, 0, -1) . ")";
                    } else {
                        $roundSQL = "AND serie.xRunde = {$round}";
                    }
                    // read all valid results (per athlet)
                    $result = mysql_query("\r\n                SELECT\r\n                    resultat.Leistung\r\n                    , resultat.Info\r\n                    , serienstart.xSerienstart\r\n                    , serienstart.xSerie\r\n                FROM\r\n                    resultat\r\n                    , serienstart\r\n                    , serie\r\n                WHERE resultat.xSerienstart = serienstart.xSerienstart\r\n                AND serienstart.xSerie = serie.xSerie\r\n                {$roundSQL}\r\n                AND resultat.Leistung != 0\r\n                ORDER BY\r\n                    serienstart.xSerienstart\r\n                    ,resultat.Leistung DESC\r\n            ");
                    if (mysql_errno() > 0) {
                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                    } else {
                        // initialize variables
                        $leistung = 0;
                        $serienstart = 0;
                        $serie = 0;
                        $topX = 0;
                        $totX = 0;
                        $ss = 0;
                        // athlete's ID
                        $tt = FALSE;
                        // top result check
                        // process every result
                        while ($row = mysql_fetch_row($result)) {
                            // new athlete: save last athlete's data
                            if ($ss != $row[2] && $ss != 0) {
                                if ($leistung != 0) {
                                    // add one row per athlete to temp table
                                    mysql_query("\r\n                                INSERT INTO tempresult\r\n                                VALUES(\r\n                                    {$serienstart}\r\n                                    , {$serie}\r\n                                    , {$leistung}\r\n                                    , {$topX}\r\n                                    , {$totX})\r\n                            ");
                                    if (mysql_errno() > 0) {
                                        // DB error
                                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                    }
                                }
                                // initialize variables
                                $leistung = 0;
                                $serienstart = 0;
                                $serie = 0;
                                $totX = 0;
                                $topX = 0;
                                $tt = FALSE;
                            }
                            // save data of current athlete's top result
                            if ($tt == FALSE && strstr($row[1], 'O')) {
                                $leistung = $row[0];
                                $serienstart = $row[2];
                                $serie = $row[3];
                                $topX = substr_count($row[1], 'X');
                                $tt = TRUE;
                            }
                            // count total invalid attempts
                            $totX = $totX + substr_count($row[1], 'X');
                            $ss = $row[2];
                            // keep athlete's ID
                        }
                        mysql_free_result($result);
                        // insert last pending data in temp table
                        if ($ss != 0 && $leistung != 0) {
                            mysql_query("\r\n                        INSERT INTO tempresult\r\n                        VALUES(\r\n                            {$serienstart}\r\n                            , {$serie}\r\n                            , {$leistung}\r\n                            , {$topX}\r\n                            , {$totX})\r\n                    ");
                            if (mysql_errno() > 0) {
                                // DB error
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            }
                        }
                    }
                    if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                        // eval per heat
                        $order = "xSerie ,";
                    } else {
                        // default: rank results from all heats together
                        $order = "";
                    }
                    // Read rows from temporary table ordered by performance,
                    // nbr of invalid attempts for top performance and
                    // total nbr of invalid attempts to determine ranking.
                    $result = mysql_query("\r\n                SELECT\r\n                    xSerienstart\r\n                    , xSerie\r\n                    , Leistung\r\n                    , TopX\r\n                    , TotalX\r\n                FROM\r\n                    tempresult\r\n                ORDER BY\r\n                    {$order}\r\n                    Leistung DESC\r\n                    ,TopX ASC\r\n                    ,TotalX ASC\r\n            ");
                    if (mysql_errno() > 0) {
                        // DB error
                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                    } else {
                        // initialize variables
                        $heat = 0;
                        $perf = 0;
                        $topX = 0;
                        $totalX = 0;
                        $i = 0;
                        $rank = 0;
                        // set rank for every athlete
                        while ($row = mysql_fetch_row($result)) {
                            if ($eval == $cfgEvalType[$strEvalTypeHeat] && $heat != $row[1]) {
                                $i = 0;
                                // restart ranking
                                $perf = 0;
                                $topX = 0;
                                $totalX = 0;
                            }
                            $j++;
                            // increment ranking
                            if ($perf != $row[2] || $topX != $row[3] || $totalX != $row[4]) {
                                $rank = $j;
                                // next rank (only if not same performance)
                            }
                            mysql_query("\r\n                        UPDATE serienstart SET\r\n                            Rang = {$rank}\r\n                        WHERE xSerienstart = {$row['0']}\r\n                    ");
                            if (mysql_errno() > 0) {
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            }
                            $heat = $row[1];
                            // keep current heat ID
                            $perf = $row[2];
                            $topX = $row[3];
                            $totalX = $row[4];
                        }
                        mysql_free_result($result);
                    }
                    mysql_query("DROP TABLE IF EXISTS tempresult");
                    if (mysql_errno() > 0) {
                        // DB error
                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                    }
                }
                // ET DB error (create temp table)
                // read all starting athletes with no valid result (rank=0)
                // and add disqualification code
                $result = mysql_query("\r\n            SELECT DISTINCT\r\n                serienstart.xSerienstart\r\n            FROM\r\n                resultat\r\n                , serienstart\r\n                , serie\r\n            WHERE resultat.xSerienstart = serienstart.xSerienstart\r\n            AND serienstart.xSerie = serie.xSerie\r\n            AND serienstart.Rang = 0\r\n            AND serie.xRunde = {$round}\r\n            AND resultat.Leistung >= 0\r\n        ");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    //
                    while ($row = mysql_fetch_row($result)) {
                        // check if "disqualified" result already there
                        $res = mysql_query("\r\n                    SELECT\r\n                        xResultat\r\n                    FROM\r\n                        resultat\r\n                    WHERE xSerienstart = {$row['0']}\r\n                    AND (Leistung = " . $cfgInvalidResult['DSQ']['code'] . "OR Leistung = " . $cfgInvalidResult['NRS']['code'] . ")");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            if (mysql_num_rows($res) <= 0) {
                                mysql_query("\r\n                            INSERT INTO\r\n                                resultat\r\n                            SET\r\n                                Leistung = " . $cfgInvalidResult['NRS']['code'] . "\r\n                                , Info = '{$cfgResultsHighOut}'\r\n                                , xSerienstart = {$row['0']}\r\n                        ");
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                            mysql_free_result($res);
                        }
                    }
                    mysql_free_result($result);
                }
                mysql_query("UNLOCK TABLES");
            }
            // ET DB error (drop temp table)
            AA_results_setNotStarted($round);
            // update athletes with no result
            AA_utils_changeRoundStatus($round, $cfgRoundStatus['results_done']);
            if (!empty($GLOBALS['AA_ERROR'])) {
                AA_printErrorMsg($GLOBALS['AA_ERROR']);
            }
        }
        //
        // calculate ranking points if needed
        //
        if ($_GET['arg'] == 'results_done' || $_POST['arg'] == 'save_rank') {
            AA_utils_calcRankingPoints($round);
        }
        if ($_POST['arg'] == 'save_remark') {
            AA_utils_saveRemark($_POST['item'], $_POST['remark'], $_POST['xAthlete']);
        }
        //
        // print HTML page header
        //
        AA_results_printHeader($presets['category'], $presets['event'], $round);
        $mergedMain = AA_checkMainRound($round);
        if ($mergedMain != 1) {
            // read round data
            if ($round > 0 && $prog_mode != 2) {
                $status = AA_getRoundStatus($round);
                // No action yet
                if ($status == $cfgRoundStatus['open'] || $status == $cfgRoundStatus['enrolement_done'] || $status == $cfgRoundStatus['heats_in_progress']) {
                    AA_printWarningMsg($strHeatsNotDone);
                } else {
                    if ($status == $cfgRoundStatus['enrolement_pending']) {
                        AA_printWarningMsg($strEnrolementNotDone);
                    } else {
                        if ($status >= $cfgRoundStatus['heats_done']) {
                            AA_heats_printNewStart($presets['event'], $round, "event_results.php");
                            // display all athletes
                            $result = mysql_query("\r\n            SELECT rt.Name\r\n                , rt.Typ\r\n                , s.xSerie\r\n                , s.Bezeichnung\r\n                , ss.xSerienstart\r\n                , ss.Position\r\n                , ss.Rang\r\n                , a.Startnummer\r\n                , at.Name\r\n                , at.Vorname\r\n                , at.Jahrgang\r\n                , if('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo))   \r\n                , LPAD(s.Bezeichnung,5,'0') as heatid\r\n                , rs.xResultat\r\n                , rs.Leistung\r\n                , rs.Info\r\n                , at.Land\r\n                , ss.Bemerkung\r\n                , at.xAthlet\r\n                , r.xRunde \r\n                , ss.RundeZusammen  \r\n            FROM\r\n                runde AS r\r\n                , serie AS s\r\n                , serienstart AS ss\r\n                , start AS st\r\n                , anmeldung AS a\r\n                , athlet AS at\r\n                , verein AS v\r\n            LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n            LEFT JOIN rundentyp AS rt\r\n                ON rt.xRundentyp = r.xRundentyp\r\n            LEFT JOIN resultat AS rs\r\n                ON rs.xSerienstart = ss.xSerienstart\r\n            WHERE r.xRunde = {$round}\r\n            AND s.xRunde = r.xRunde\r\n            AND ss.xSerie = s.xSerie\r\n            AND st.xStart = ss.xStart\r\n            AND a.xAnmeldung = st.xAnmeldung\r\n            AND at.xAthlet = a.xAthlet\r\n            AND v.xVerein = at.xVerein\r\n            ORDER BY\r\n                heatid\r\n                , ss.Position\r\n                , rs.xResultat DESC\r\n        ");
                            if (mysql_errno() > 0) {
                                // DB error
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            } else {
                                AA_results_printMenu($round, $status, $prog_mode, 'high');
                                // initialize variables
                                $a = 0;
                                $h = 0;
                                $i = 0;
                                if (!empty($_GET['athlete'])) {
                                    $_POST['athlete'] = $_GET['athlete'];
                                }
                                if (empty($_POST['athlete']) || mysql_num_rows($result) < $_POST['athlete']) {
                                    $_POST['athlete'] = 1;
                                    // focus to first athlete
                                }
                                $rowclass = 'odd';
                                if ($cfgProgramMode[$prog_mode]['name'] == $strProgramModeBackoffice) {
                                    $focus = 0;
                                    // keep focus on this athlete if Backoffice Mode
                                } else {
                                    $focus = 1;
                                    // focus on next athlete if Field Mode
                                }
                                ?>
<p/>

<table class='dialog'>
<?php 
                                $btn = new GUI_Button('', '');
                                // create button object
                                while ($row = mysql_fetch_row($result)) {
                                    if ($row[20] > 0) {
                                        $singleRound = $row[20];
                                    } else {
                                        $singleRound = $row[19];
                                    }
                                    // terminate last row if new athlete and not first item
                                    if ($a != $row[4] && $i != 0) {
                                        if ($_POST['athlete'] == $i + 1 && $cfgProgramMode[$prog_mode]['name'] == $strProgramModeField) {
                                            if ($row[15] == 'XXX' && !$click) {
                                                $_POST['athlete'] = $_POST['athlete'] + 1;
                                            }
                                        }
                                        if ($_POST['athlete'] == $i) {
                                            echo "<td>";
                                            $btn->set("event_results.php?arg=del_start&item={$a}&round={$round}", $strDelete);
                                            $btn->printButton();
                                            echo "</td>";
                                        }
                                        echo "</tr>";
                                    }
                                    /*
                                     *  Heat headerline
                                     */
                                    if ($h != $row[2]) {
                                        $h = $row[2];
                                        // keep heat ID
                                        if (is_null($row[0])) {
                                            // only one round
                                            $title = "{$strFinalround}";
                                        } else {
                                            // more than one round
                                            $title = "{$row['0']}";
                                        }
                                        $c = 0;
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            $c = 1;
                                            // increment colspan to include ranking
                                        }
                                        ?>
    <tr>
        <form action='event_results.php#heat_<?php 
                                        echo $row[3];
                                        ?>
' method='post'
            name='heat_id_<?php 
                                        echo $h;
                                        ?>
'>

        <th class='dialog' colspan='<?php 
                                        echo 7 + $c;
                                        ?>
' />
            <?php 
                                        echo $title;
                                        ?>
            <input type='hidden' name='arg' value='change_heat_name' />
            <input type='hidden' name='round' value='<?php 
                                        echo $round;
                                        ?>
' />
            <input type='hidden' name='singleRound' value='<?php 
                                        echo $singleRound;
                                        ?>
' />    
            <input type='hidden' name='item' value='<?php 
                                        echo $row[2];
                                        ?>
' />
            <input class='nbr' type='text' name='id' maxlength='2'
                value='<?php 
                                        echo $row[3];
                                        ?>
'
                onChange='document.heat_id_<?php 
                                        echo $h;
                                        ?>
.submit()' />
                <a name='heat_<?php 
                                        echo $row[3];
                                        ?>
' />
        </th> 
        
        </form>
    </tr>  
    <tr>
        <th class='dialog'><?php 
                                        echo $strPositionShort;
                                        ?>
</th>
        <th class='dialog' colspan='2'><?php 
                                        echo $strAthlete;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        echo $strYearShort;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        echo $strCountry;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        if ($svm) {
                                            echo $strTeam;
                                        } else {
                                            echo $strClub;
                                        }
                                        ?>
</th>
<?php 
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            ?>
        <th class='dialog'><?php 
                                            echo $strRank;
                                            ?>
</th>
<?php 
                                        }
                                        ?>
        <th class='dialog' ><?php 
                                        echo $strResultRemark;
                                        ?>
</th>         
        <th class='dialog' colspan='2'><?php 
                                        echo $strPerformance;
                                        ?>
</th>  
    </tr>
<?php 
                                    }
                                    // ET new heat
                                    /*
                                     * Athlete data lines
                                     */
                                    if ($a != $row[4]) {
                                        $a = $row[4];
                                        // keep athlete ID
                                        $i++;
                                        // increment athlete counter
                                        $l = 0;
                                        // reset result counter
                                        if ($_POST['athlete'] == $i) {
                                            // active item
                                            $rowclass = 'active';
                                        } else {
                                            if ($row[5] % 2 == 0) {
                                                // even row numer
                                                $rowclass = 'even';
                                            } else {
                                                // odd row number
                                                $rowclass = 'odd';
                                            }
                                        }
                                        if ($rowclass == 'active') {
                                            ?>
    <tr class='active'>
<?php 
                                        } else {
                                            ?>
    <tr class='<?php 
                                            echo $rowclass;
                                            ?>
'
        onclick='selectAthlete(<?php 
                                            echo $i;
                                            ?>
)'>
<?php 
                                        }
                                        ?>
        <td class='forms_right'><?php 
                                        echo $row[5];
                                        ?>
</td>
        <td class='forms_right'><?php 
                                        echo $row[7];
                                        /* start nbr */
                                        ?>
</td>
        <td nowrap><?php 
                                        echo $row[8] . " " . $row[9];
                                        /* name */
                                        ?>
</td>
        <td class='forms_ctr'><?php 
                                        echo AA_formatYearOfBirth($row[10]);
                                        ?>
</td>
        <td><?php 
                                        echo $row[16] != '' && $row[16] != '-' ? $row[16] : '&nbsp;';
                                        ?>
</td>
        <td nowrap><?php 
                                        echo $row[11];
                                        /* club */
                                        ?>
</td>
   
<?php 
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            if ($_POST['athlete'] == $i) {
                                                ?>
        <form action='event_results.php' method='post'
            name='rank'>
        <td>
            <input type='hidden' name='arg' value='save_rank' />
            <input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
             <input type='hidden' name='singleRound' value='<?php 
                                                echo $singleRound;
                                                ?>
' />    
            <input type='hidden' name='athlete' value='<?php 
                                                echo $i + $focus;
                                                ?>
' />
            <input type='hidden' name='item' value='<?php 
                                                echo $row[4];
                                                ?>
' />
            <input class='nbr' type='text' name='rank' maxlength='3'
                value='<?php 
                                                echo $row[6];
                                                ?>
' onChange='document.rank.submit()' />
        </td>
        </form>
<?php 
                                            } else {
                                                echo "<td>" . $row[6] . "</td>";
                                            }
                                            echo "<td>" . $row[17] . "</td>";
                                        } else {
                                            ?>
 
                        

<form action='event_results.php' method='post'
            name='remark_<?php 
                                            echo $i;
                                            ?>
'>
        <td>
            <input type='hidden' name='arg' value='save_remark' />
            <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
             <input type='hidden' name='singleRound' value='<?php 
                                            echo $singleRound;
                                            ?>
' />    
            <input type='hidden' name='athlete' value='<?php 
                                            echo $i + $focus;
                                            ?>
' />
            <input type='hidden' name='item' value='<?php 
                                            echo $row[4];
                                            ?>
' />
            <input type='hidden' name='xAthlete' value='<?php 
                                            echo $row[18];
                                            ?>
' />    
            <input class='textshort' type='text' name='remark' maxlength='5'
                value='<?php 
                                            echo $row[17];
                                            ?>
' onchange='document.remark_<?php 
                                            echo $i;
                                            ?>
.submit()' />
        </td>
        </form>  
       
  
      
                   <?php 
                                        }
                                    }
                                    // ET new athlete
                                    $new_perf = '';
                                    if ($_POST['athlete'] == $i) {
                                        if (is_null($row[14])) {
                                            // no result yet: show form
                                            $last_perf = 0;
                                        } else {
                                            $last_perf = $row[14];
                                        }
                                        $item = '';
                                        if ($l == 0) {
                                            // read all performances achieved in current heat and
                                            // better than last entered performance
                                            if ($cfgProgramMode[$prog_mode]['name'] == $strProgramModeField) {
                                                if (in_array($row[15], $cfgResultsHighStayDecentral)) {
                                                    $new_perf = AA_formatResultMeter($last_perf);
                                                    $new_info = $row[15];
                                                    $item = $row[13];
                                                } else {
                                                    $new_perf = getNextHeight($row[2], $last_perf);
                                                    $new_info = '';
                                                }
                                            } else {
                                                if (in_array($row[15], $cfgResultsHighStay)) {
                                                    $new_perf = AA_formatResultMeter($last_perf);
                                                    $new_info = $row[15];
                                                    $item = $row[13];
                                                } else {
                                                    $new_perf = getNextHeight($row[2], $last_perf);
                                                    $new_info = '';
                                                }
                                            }
                                            ?>
        <form action='event_results.php' method='post'
            name='perf'>
        <td nowrap colspan='2'> 
            <input type='hidden' name='arg' value='save_res' />
            <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
             <input type='hidden' name='singleRound' value='<?php 
                                            echo $singleRound;
                                            ?>
' />    
            <input type='hidden' name='athlete' value='<?php 
                                            echo $i + $focus;
                                            ?>
' />
            <input type='hidden' name='start' value='<?php 
                                            echo $row[4];
                                            ?>
' />
             <input type='hidden' name='xSerie' value='<?php 
                                            echo $row[2];
                                            ?>
' />  
            <input type='hidden' name='item' value='<?php 
                                            echo $item;
                                            ?>
' />
            <input class='perfheight' type='text' name='perf' maxlength='5'
                value='<?php 
                                            echo $new_perf;
                                            ?>
'
                    onChange='checkSubmit(document.perf)' />  
            <input class='texttiny' type='text' name='attempts' maxlength='3'
                value='<?php 
                                            echo $new_info;
                                            ?>
'
                    onChange='document.perf.submit()' onBlur='document.perf.submit()' />
        </td>
        </form>   
        
        
                        <?php 
                                        }
                                        if (is_null($row[14]) == false && empty($item)) {
                                            // next height
                                            ?>
        <td nowrap>
            <?php 
                                            echo AA_formatResultMeter($row[14]) . "<br/>( {$row['15']} )";
                                            ?>
        </td>
        <td>
                        <?php 
                                            $btn = new GUI_Button("event_results.php?arg=delete&round={$round}&item={$row['13']}&athlete={$i}", "X");
                                            $btn->printButton();
                                            ?>
        </td>
                        <?php 
                                        }
                                        $l++;
                                    } else {
                                        if (is_null($row[14]) == false) {
                                            echo "<td colspan='2' nowrap>" . AA_formatResultMeter($row[14]) . " ( {$row['15']} )</td>";
                                        }
                                    }
                                }
                                if ($a != 0) {
                                    if ($_POST['athlete'] == $i) {
                                        echo "<td>";
                                        $btn->set("event_results.php?arg=del_start&item={$a}&round={$round}", $strDelete);
                                        $btn->printButton();
                                        echo "</td>";
                                    }
                                    echo "</tr>";
                                }
                                ?>
           
            
            
            
</table>
  
                 
            <?php 
                                mysql_free_result($result);
                            }
                            // ET DB error
                        }
                    }
                }
            } else {
                if ($round > 0 && $prog_mode == 2) {
                    $status = AA_getRoundStatus($round);
                    // No action yet
                    if ($status == $cfgRoundStatus['open'] || $status == $cfgRoundStatus['enrolement_done'] || $status == $cfgRoundStatus['heats_in_progress']) {
                        AA_printWarningMsg($strHeatsNotDone);
                    } else {
                        if ($status == $cfgRoundStatus['enrolement_pending']) {
                            AA_printWarningMsg($strEnrolementNotDone);
                        } else {
                            if ($status >= $cfgRoundStatus['heats_done']) {
                                AA_heats_printNewStart($presets['event'], $round, "event_results.php");
                                $ph = 0;
                                // find max height per athlete
                                $sql_max_h = "SELECT \r\n                 LPAD(s.Bezeichnung,5,'0') as heatid\r\n                , count(*) \r\n            FROM\r\n                runde AS r\r\n                LEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n                LEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n                LEFT JOIN start AS st ON (st.xStart = ss.xStart) \r\n                LEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n                LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n                LEFT JOIN verein AS v ON (v.xVerein = at.xVerein)\r\n                LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                LEFT JOIN rundentyp AS rt ON rt.xRundentyp = r.xRundentyp\r\n                LEFT JOIN resultat AS rs ON rs.xSerienstart = ss.xSerienstart\r\n            WHERE r.xRunde = {$round}              \r\n            GROUP BY ss.xSerienstart\r\n            ORDER BY\r\n                heatid\r\n                , ss.Position DESC\r\n                , rs.xResultat";
                                $res_max_h = mysql_query($sql_max_h);
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    $ph = 0;
                                    //  height column
                                    $starts = 0;
                                    // all started athletes
                                    while ($row_max_h = mysql_fetch_row($res_max_h)) {
                                        $starts++;
                                        if ($row_max_h[1] > $ph) {
                                            $ph = $row_max_h[1];
                                        }
                                    }
                                }
                                // fill last infos (included previous info by 'XXX') in an array
                                $sql_info = "SELECT rt.Name\r\n                , rt.Typ\r\n                , s.xSerie\r\n                , s.Bezeichnung\r\n                , ss.xSerienstart\r\n                , ss.Position\r\n                , ss.Rang\r\n                , a.Startnummer\r\n                , at.Name\r\n                , at.Vorname\r\n                , at.Jahrgang\r\n                , if('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo))   \r\n                , LPAD(s.Bezeichnung,5,'0') as heatid\r\n                , rs.xResultat\r\n                , rs.Leistung\r\n                , rs.Info\r\n                , at.Land\r\n                , ss.Bemerkung\r\n                , at.xAthlet\r\n                , r.xRunde \r\n                , ss.RundeZusammen  \r\n            FROM\r\n                runde AS r\r\n                LEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n                LEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n                LEFT JOIN start AS st ON (st.xStart = ss.xStart) \r\n                LEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n                LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n                LEFT JOIN verein AS v ON (v.xVerein = at.xVerein)\r\n                LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                LEFT JOIN rundentyp AS rt ON rt.xRundentyp = r.xRundentyp\r\n                LEFT JOIN resultat AS rs ON rs.xSerienstart = ss.xSerienstart  \r\n            WHERE r.xRunde = {$round}      \r\n              ORDER BY\r\n                heatid\r\n                , ss.Position \r\n                , rs.xResultat\r\n                \r\n                ";
                                $res_info = mysql_query($sql_info);
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    $c = 0;
                                    $arr_info = array();
                                    $arr_info_remark = array();
                                    // previous info 'p'
                                    $count_results = 0;
                                    $count_ends = 0;
                                    // athletes with results 'XXX'
                                    while ($row_info = mysql_fetch_row($res_info)) {
                                        if ($row_info[4] != $a && $c > 0) {
                                            if (!empty($keep_info)) {
                                                if ($c == $ph) {
                                                    $arr_info[] = $keep_info;
                                                    $arr_info_remark[] = '';
                                                    $count_results++;
                                                } else {
                                                    if ($keep_info == 'XXX') {
                                                        $arr_info[] = $keep_info;
                                                        $arr_info_remark[] = 'p';
                                                        // previous
                                                        $count_results++;
                                                    } else {
                                                        $arr_info[] = '';
                                                        $arr_info_remark[] = '';
                                                        $count_results++;
                                                    }
                                                }
                                                $c = 0;
                                            }
                                        }
                                        $c++;
                                        if ($row_info[15] == 'XXX') {
                                            $count_ends++;
                                        }
                                        $a = $row_info[4];
                                        $keep_info = $row_info[15];
                                    }
                                    if (!empty($keep_info)) {
                                        if ($c == $ph) {
                                            $arr_info[] = $keep_info;
                                            $arr_info_remark[] = '';
                                            $count_results++;
                                        } else {
                                            if ($keep_info == 'XXX') {
                                                $arr_info[] = $keep_info;
                                                $arr_info_remark[] = 'p';
                                                // previous
                                                $count_results++;
                                            } else {
                                                $arr_info[] = '';
                                                $arr_info_remark[] = '';
                                                $count_results++;
                                            }
                                        }
                                    }
                                }
                                // array for infos to jump
                                $arr_info_toJump = array();
                                foreach ($arr_info as $key => $val) {
                                    if (!in_array($val, $cfgResultsHighStayDecentralEnd)) {
                                        $arr_info_toJump[$key] = $val;
                                    }
                                }
                                // find out new column (= newHight )
                                $sql_hight = "SELECT    \r\n                LPAD(s.Bezeichnung,5,'0') as heatid                 \r\n                , rs.Leistung\r\n                , rs.Info                   \r\n                , d.Code  \r\n            FROM\r\n                runde AS r\r\n                LEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n                LEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n                LEFT JOIN start AS st ON (st.xStart = ss.xStart) \r\n                LEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n                LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n                LEFT JOIN verein AS v ON (v.xVerein = at.xVerein)\r\n                LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                LEFT JOIN rundentyp AS rt ON rt.xRundentyp = r.xRundentyp\r\n                LEFT JOIN resultat AS rs ON rs.xSerienstart = ss.xSerienstart\r\n                LEFT JOIN wettkampf AS w ON (w.xWettkampf = r.xWettkampf)  \r\n                LEFT JOIN disziplin AS d ON (d.xDisziplin = w.xDisziplin)   \r\n            WHERE r.xRunde = {$round}                 \r\n              ORDER BY\r\n                heatid\r\n                , rs.Leistung DESC\r\n                , ss.Position ASC\r\n                ";
                                $res_hight = mysql_query($sql_hight);
                                $e = 0;
                                // count performance when is finished with this high
                                $z = 0;
                                $first = true;
                                $disCode = 0;
                                while ($row_hight = mysql_fetch_row($res_hight)) {
                                    if ($perf_keep != $row_hight[1] && !$first) {
                                        $z++;
                                        if ($z > 1) {
                                            break;
                                        } else {
                                            $e_keep = $e;
                                            $e = 0;
                                        }
                                    }
                                    $first = false;
                                    if (in_array($row_hight[2], $cfgResultsHighStayDecentralEnd)) {
                                        if ($row_hight[2] != 'XXX') {
                                            $e++;
                                        }
                                    }
                                    $perf_keep = $row_hight[1];
                                    $disCode = $row_hight[3];
                                }
                                $newHight = false;
                                if (is_null($e_keep)) {
                                    $e_keep = $e;
                                }
                                if ($e_keep == $starts - $count_ends) {
                                    $newHight = true;
                                }
                                if (empty($_POST)) {
                                    if ($ph > $max) {
                                        $max = $ph;
                                    }
                                }
                                if (empty($_POST)) {
                                    $y = 0;
                                    while ($row = mysql_fetch_row($res_c_h)) {
                                        $name = "hight_" . $y;
                                        $hiddenName = "hiddeHight_" . $y;
                                        $performance_new = AA_formatResultMeter($row[0]);
                                        $_POST[$name] = $performance_new;
                                        $_POST[$hiddenName] = $performance_new;
                                        $y++;
                                    }
                                }
                                // found active athlete
                                $a_activ = 0;
                                $flen = 0;
                                $f_len_keep = 0;
                                $r_f_len = 0;
                                $r_f_len_keep = 0;
                                $a_activ_set = false;
                                $f = 0;
                                $reset_activ = false;
                                for ($r = $starts - 1; $r >= 0; $r--) {
                                    if ($arr_info[$r] == '' || $arr_info_remark[$r] == 'p') {
                                        $f++;
                                    } else {
                                        if ($f > 0) {
                                            $a_activ = $r + 2;
                                            for ($j = $a_activ - 1; $j < $starts; $j++) {
                                                if ($arr_info_remark[$a_activ - 1] == 'p') {
                                                    $a_activ++;
                                                }
                                            }
                                            $a_activ_set = true;
                                        }
                                        if ($a_activ > $starts) {
                                            $a_activ_set = false;
                                            $reset_activ = true;
                                        }
                                        break;
                                    }
                                }
                                if (!$a_activ_set) {
                                    if ($newHight) {
                                        for ($r = 0; $r < $starts; $r++) {
                                            if ($arr_info[$r] != 'XXX') {
                                                $a_activ = $r + 1;
                                                $a_activ_set = true;
                                                break;
                                            }
                                        }
                                        if (!$a_activ_set) {
                                            $a_activ = 1;
                                        }
                                    } elseif ($reset_activ) {
                                        $val_keep = '';
                                        foreach ($arr_info_toJump as $key => $val) {
                                            if (strlen($val) == 1) {
                                                $arr_info_toJump_1[$key] = $val;
                                            } elseif (strlen($val) == 2) {
                                                $arr_info_toJump_2[$key] = $val;
                                            }
                                        }
                                        if (count($arr_info_toJump_1) > 0) {
                                            foreach ($arr_info_toJump_1 as $key => $val) {
                                                $a_activ = $key + 1;
                                                break;
                                            }
                                        } else {
                                            foreach ($arr_info_toJump_2 as $key => $val) {
                                                $a_activ = $key + 1;
                                                break;
                                            }
                                        }
                                    } else {
                                        for ($r = $starts - 1; $r >= 0; $r--) {
                                            if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                $athleteValidFirst = false;
                                            } else {
                                                $f_len = strlen($arr_info[$r]);
                                                $r_f_len = $r;
                                                if ($f_len_keep > 0) {
                                                    if ($f_len_keep < $f_len) {
                                                        $a_activ = $r_f_len_keep + 1;
                                                        break;
                                                    } elseif ($f_len_keep = $f_len) {
                                                        $a_activ = $r_f_len + 1;
                                                    } elseif ($f_len_keep > $f_len) {
                                                        break;
                                                    }
                                                } else {
                                                    $a_activ = $r_f_len + 1;
                                                }
                                                $f_len_keep = $f_len;
                                                $r_f_len_keep = $r_f_len;
                                            }
                                        }
                                    }
                                }
                                if (is_null($_POST['athlete'])) {
                                    $_POST['athlete'] = $a_activ;
                                }
                                $aClick = false;
                                if (isset($_POST['result'])) {
                                    // this means that user makes a click to a athlete
                                    $aClick = true;
                                }
                                if (isset($_GET['arg']) && $_GET['arg'] == 'delete') {
                                    $aClick = true;
                                }
                                $athleteValidAfter = true;
                                if ($_POST['athlete'] >= 1 && !$aClick) {
                                    $athleteValidAfter = true;
                                    if ($starts != $count_ends) {
                                        if (count($arr_info) == $starts) {
                                            for ($r = $starts - 1; $r >= 0; $r--) {
                                                if ($r < $_POST['athlete'] - 1) {
                                                    break;
                                                }
                                                if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                    $athleteValidAfter = false;
                                                } else {
                                                    $athleteValidAfter = true;
                                                    break;
                                                }
                                            }
                                            if ($_POST['athlete'] > $starts) {
                                                $athleteValidAfter = false;
                                            }
                                        }
                                    } else {
                                        $athleteValidAfter = false;
                                        if (!$aClick) {
                                            $_POST['athlete'] = 1;
                                            $a_activ = 1;
                                        }
                                    }
                                    if (!$athleteValidAfter && !$aClick && !$newHight) {
                                        // set to first athlete when no valid athletes after
                                        $_POST['athlete'] = 1;
                                    }
                                }
                                // find out first valid athlete
                                $athleteValidFirst = true;
                                $a_first = 0;
                                if ($_POST['athlete'] >= 1 && !$aClick) {
                                    $athleteValidFirst = true;
                                    if ($starts != $count_ends) {
                                        if (count($arr_info) == $starts) {
                                            for ($r = 0; $r < $starts; $r++) {
                                                if ($arr_info[$r] == 'XXX') {
                                                    $athleteValidFirst = false;
                                                } else {
                                                    $athleteValidFirst = true;
                                                    $a_first = $r + 1;
                                                    break;
                                                }
                                            }
                                        }
                                    } else {
                                        $athleteValidAfter = false;
                                        if (!$aClick) {
                                            $_POST['athlete'] = 1;
                                            $a_activ = 1;
                                        }
                                    }
                                    if ($a_first > 0 && !$athleteValidAfter && !$click) {
                                        $_POST['athlete'] = $a_first;
                                    }
                                }
                                if (isset($_POST['result']) || $aClick) {
                                    // this means that user makes a click to a athlete
                                    $a_activ = $_POST['athlete'];
                                }
                                if ($starts == $count_ends && !$aClick) {
                                    $_POST['athlete'] = 1;
                                    $a_activ = 1;
                                }
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    AA_results_printMenu($round, $status, $prog_mode, 'high');
                                    // initialize variables
                                    $a = 0;
                                    $h = 0;
                                    $i = 0;
                                    if (!empty($_GET['athlete'])) {
                                        $_POST['athlete'] = $_GET['athlete'];
                                    }
                                    if (empty($_POST['athlete']) || $starts < $_POST['athlete']) {
                                        $_POST['athlete'] = 1;
                                        // focus to first athlete
                                    }
                                    $rowclass = 'odd';
                                    if ($cfgProgramMode[$prog_mode]['name'] == $strProgramModeBackoffice) {
                                        $focus = 0;
                                        // keep focus on this athlete if Backoffice Mode
                                    } else {
                                        $focus = 1;
                                        // focus on next athlete if Field Mode
                                    }
                                    ?>
<p/>

<table class='dialog'>
<?php 
                                    $l = 0;
                                    $newAthl = false;
                                    $flagField = false;
                                    $skip = false;
                                    $s = 0;
                                    $s_keep = 0;
                                    $k = 0;
                                    $p = 0;
                                    // all pass
                                    $btn = new GUI_Button('', '');
                                    // create button object
                                    $flagField = false;
                                    $res_info = mysql_query($sql_info);
                                    while ($row = mysql_fetch_row($res_info)) {
                                        if ($a != $row[4] && $i != 0) {
                                            // new athlete
                                            $k = 0;
                                            if ($s >= $s_keep) {
                                                $s_keep = $s;
                                            }
                                            $s = 0;
                                        }
                                        $p++;
                                        $k++;
                                        $s++;
                                        if ($row[15] == 'XXX') {
                                            $skip = true;
                                        } else {
                                            if (in_array($row[15], $cfgResultsHighStayDecentralEnd) && $ph == $k && !$newHight) {
                                                $skip = true;
                                            } else {
                                                $skip = false;
                                            }
                                        }
                                        if ($row[20] > 0) {
                                            $singleRound = $row[20];
                                        } else {
                                            $singleRound = $row[19];
                                        }
                                        // terminate last row if new athlete and not first item
                                        if ($a != $row[4] && $i != 0) {
                                            $athleteValid = true;
                                            $athleteValidAfter = true;
                                            if ($starts != $count_ends) {
                                                if (count($arr_info) == $starts) {
                                                    for ($r = $starts - 1; $r >= 0; $r--) {
                                                        if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                            $athleteValid = false;
                                                        } else {
                                                            $athleteValid = true;
                                                            break;
                                                        }
                                                    }
                                                    for ($r = $starts - 1; $r >= 0; $r--) {
                                                        if ($r < $_POST['athlete'] - 1) {
                                                            break;
                                                        }
                                                        if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                            $athleteValidAfter = false;
                                                        } else {
                                                            $athleteValidAfter = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                            } else {
                                                $athleteValid = false;
                                                $athleteValidAfter = false;
                                                if (!$aClick) {
                                                    $_POST['athlete'] = 1;
                                                    $a_activ = 1;
                                                }
                                            }
                                            if ($_POST['athlete'] == $i || !$athleteValid && $newHight && $k != 1 || $aClick && $a_activ == $i) {
                                                if (!$flagField) {
                                                    ?>
                                <form action='event_results.php' method='post'
                                            name='perf'>
                                <td nowrap colspan='2'> 
                                            <input type='hidden' name='arg' value='save_res' />
                                            <input type='hidden' name='round' value='<?php 
                                                    echo $round;
                                                    ?>
' />
                                             <input type='hidden' name='singleRound' value='<?php 
                                                    echo $singleRound;
                                                    ?>
' />    
                                            <input type='hidden' name='athlete' value='<?php 
                                                    echo $i + $focus;
                                                    ?>
' />
                                            <input type='hidden' name='start' value='<?php 
                                                    echo $a;
                                                    ?>
' />                                              
                                            <input type='hidden' name='item' value='<?php 
                                                    echo $item;
                                                    ?>
' />
                                            <input class='perfheight' type='hidden' name='perf' maxlength='5'    
                                               value='<?php 
                                                    echo $new_perf;
                                                    ?>
'
                                                     />
                                            <?php 
                                                    foreach ($_POST as $key => $val) {
                                                        $arr_key = explode('_', $key);
                                                        $hiddenName = $arr_key[0] . "_" . $arr_key[1];
                                                        ?>
                                                 <input type='hidden' name='<?php 
                                                        echo $hiddenName;
                                                        ?>
' value='<?php 
                                                        echo $val;
                                                        ?>
' /> 
                                                 <?php 
                                                    }
                                                    ?>
         
                                            <input class='texttiny' type='text' name='attempts' maxlength='3'  onfocus="this.value = '<?php 
                                                    echo $new_info;
                                                    ?>
'"
                                                value='<?php 
                                                    echo $new_info;
                                                    ?>
' />
                                             <button type='button' name="butt" onclick="document.perf.submit()">ok</button>
                                </td>
                                </form>                                              
                                          
                               <?php 
                                                    $flagField = true;
                                                    echo "<td colspan='31'>&nbsp;";
                                                    echo "</td>";
                                                    echo "<td>";
                                                    $btn->set("event_results.php?arg=del_start&item={$a}&round={$round}", $strDelete);
                                                    $btn->printButton();
                                                    echo "</td>";
                                                }
                                            }
                                            echo "</tr>";
                                        }
                                        /*
                                         *  Heat headerline
                                         */
                                        if ($h != $row[2]) {
                                            $h = $row[2];
                                            // keep heat ID
                                            if (is_null($row[0])) {
                                                // only one round
                                                $title = "{$strFinalround}";
                                            } else {
                                                // more than one round
                                                $title = "{$row['0']}";
                                            }
                                            $c = 0;
                                            if ($status == $cfgRoundStatus['results_done']) {
                                                $c = 1;
                                                // increment colspan to include ranking
                                            }
                                            ?>
    <tr>
        <form action='event_results.php#heat_<?php 
                                            echo $row[3];
                                            ?>
' method='post'
            name='heat_id_<?php 
                                            echo $h;
                                            ?>
'>

        <th class='dialog' colspan='<?php 
                                            echo 7 + $c;
                                            ?>
' />
            <?php 
                                            echo $title;
                                            ?>
            <input type='hidden' name='arg' value='change_heat_name' />
            <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
            <input type='hidden' name='singleRound' value='<?php 
                                            echo $singleRound;
                                            ?>
' />    
            <input type='hidden' name='item' value='<?php 
                                            echo $row[2];
                                            ?>
' />               
            <input class='nbr' type='text' name='id' maxlength='2'
                value='<?php 
                                            echo $row[3];
                                            ?>
'
                onchange='document.heat_id_<?php 
                                            echo $h;
                                            ?>
.submit()' />
                <a name='heat_<?php 
                                            echo $row[3];
                                            ?>
' />
        </th> 
        <?php 
                                            if (isset($_POST['max'])) {
                                                $colspanPerf = $_POST['max'] * 2 + 2;
                                            } else {
                                                $colspanPerf = $cfgCountHeight * 2 + 2;
                                            }
                                            ?>
  
            <th colspan="<?php 
                                            echo $colspanPerf;
                                            ?>
"><?php 
                                            echo $strPerformance;
                                            ?>
</th>  
         <?php 
                                            ?>
        </form>
    </tr>  
    <tr>
        <th class='dialog'><?php 
                                            echo $strPositionShort;
                                            ?>
</th>
        <th class='dialog' colspan='2'><?php 
                                            echo $strAthlete;
                                            ?>
</th>
        <th class='dialog'><?php 
                                            echo $strYearShort;
                                            ?>
</th>
        <th class='dialog'><?php 
                                            echo $strCountry;
                                            ?>
</th>
        <th class='dialog'><?php 
                                            if ($svm) {
                                                echo $strTeam;
                                            } else {
                                                echo $strClub;
                                            }
                                            ?>
</th>  
        <th class='dialog'><?php 
                                            echo $strRank;
                                            ?>
</th>   
        <th class='dialog' ><?php 
                                            echo $strResultRemark;
                                            ?>
</th>    
         
        <?php 
                                            $height_start = $cfgHeightStartJump;
                                            // default jump
                                            if ($disCode == '310') {
                                                // jump
                                                $height_start = $cfgHeightStartJump;
                                            } elseif ($disCode == '320') {
                                                $height_start = $cfgHeightStartPole;
                                                // pole
                                            }
                                            ?>
        <form action='event_results.php' method='post' name='hight_id'> 
        <input type='hidden' name='arg' value='save_height' />
        <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
        <input type='hidden' name='heat' value='<?php 
                                            echo $row[2];
                                            ?>
' />  
        <input type='hidden' name='singleRound' value='<?php 
                                            echo $singleRound;
                                            ?>
' />          
                  
        <?php 
                                            $count_height = AA_checkHeight($round, $row[2]);
                                            $arr_height = array();
                                            if ($count_height > 0) {
                                                $max = $count_height;
                                                $sql = "SELECT h.Hoehe \r\n                    FROM \r\n                         hoehe AS h\r\n                         LEFT JOIN runde AS r ON (r.xRunde = h.xRunde)\r\n                         LEFT JOIN wettkampf AS w ON (w.xWettkampf = r.xWettkampf) \r\n                    WHERE \r\n                         h.xRunde = " . $round . " \r\n                         AND h.xSerie = " . $row[2] . " \r\n                         AND w.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                         ORDER BY hoehe";
                                                $res = mysql_query($sql);
                                                if (mysql_errno() > 0) {
                                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                                } else {
                                                    $g = 0;
                                                    while ($row_height = mysql_fetch_row($res)) {
                                                        $arr_height[] = $row_height[0];
                                                        $height = AA_formatResultMeter($row_height[0]);
                                                        $dis = '';
                                                        // disable the hight done
                                                        if ($newHight) {
                                                            $ph_vgl = $ph - 1;
                                                            if ($g <= $ph_vgl) {
                                                                $dis = 'disabled="disabled"';
                                                            }
                                                        } else {
                                                            $ph_vgl = ceil($ph - 1);
                                                            if ($g <= $ph_vgl) {
                                                                $dis = 'disabled="disabled"';
                                                            }
                                                            if ($count_results == 0 && $g == 0) {
                                                                $dis = '';
                                                            }
                                                        }
                                                        ?>
   
                                   
                            <input class='perfheight' type='hidden' name='hiddenHeight_<?php 
                                                        echo $g;
                                                        ?>
' maxlength='5' value='<?php 
                                                        echo $height;
                                                        ?>
'/>
                            <th class='dialog' colspan='2'><input class='perfheight' type='text' name='hight_<?php 
                                                        echo $g;
                                                        ?>
' maxlength='5'
                                value='<?php 
                                                        echo $height;
                                                        ?>
' onchange='document.hight_id.submit()' <?php 
                                                        echo $dis;
                                                        ?>
 /></th>   
                           
                            <?php 
                                                        $g++;
                                                    }
                                                }
                                            } else {
                                                $max = $cfgCountHeight;
                                                for ($g = 0; $g < $cfgCountHeight; $g++) {
                                                    $_POST['start'] = 0;
                                                    $height_start_tmp = new PerformanceAttempt($height_start);
                                                    $height_start_tmp = $height_start_tmp->getPerformance();
                                                    $arr_height[] = $height_start_tmp;
                                                    AA_setHeight($height_start_tmp, $round, $row[2], '');
                                                    ?>
     
                                   
                        <input class='perfheight' type='hidden' name='hiddenHeight_<?php 
                                                    echo $g;
                                                    ?>
' maxlength='5' value='<?php 
                                                    echo sprintf("%.2f", $height_start);
                                                    ?>
'/>
                            <th class='dialog' colspan='2'><input class='perfheight' type='text' name='hight_<?php 
                                                    echo $g;
                                                    ?>
' maxlength='5'
                                value='<?php 
                                                    echo sprintf("%.2f", $height_start);
                                                    ?>
' onchange='document.hight_id.submit()' /></th>
                          
                        <?php 
                                                    if ($disCode == '310') {
                                                        // jump
                                                        $height_start += $cfgHeightDiffJump;
                                                    } elseif ($disCode == '320') {
                                                        $height_start += $cfgHeightDiffPole;
                                                        // pole
                                                    } else {
                                                        $height_start += $cfgHeightDiffJump;
                                                    }
                                                }
                                            }
                                            ?>
  
                    
                <input class='perfheight' type='hidden' name='hiddenHeight_<?php 
                                            echo $g;
                                            ?>
' maxlength='5' value=''/> 
                    <th class='dialog' colspan='2'><input class='perfheight' type='text' name='hight_<?php 
                                            echo $max;
                                            ?>
' maxlength='5'
                        value='' onchange='document.hight_id.submit()' /></th>   
                <input type='hidden' name='max' value='<?php 
                                            echo $max;
                                            ?>
' />  
                <input type='hidden' name='disCode' value='<?php 
                                            echo $disCode;
                                            ?>
' />  
                 </form>   
                 
    </tr>
<?php 
                                        }
                                        // ET new heat
                                        /*
                                         * Athlete data lines   
                                         */
                                        if ($newAthl) {
                                            if ($k == $ph) {
                                                // k = results per athlete  ph = hight column
                                                $athleteValid = true;
                                                $athleteValidAfter = true;
                                                if ($starts != $count_ends) {
                                                    if (count($arr_info) == $starts) {
                                                        for ($r = $starts - 1; $r >= 0; $r--) {
                                                            if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                                $athleteValid = false;
                                                            } else {
                                                                $athleteValid = true;
                                                                break;
                                                            }
                                                        }
                                                        for ($r = $starts - 1; $r >= 0; $r--) {
                                                            if ($r < $_POST['athlete'] - 1) {
                                                                break;
                                                            }
                                                            if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                                $athleteValidAfter = false;
                                                            } else {
                                                                $athleteValidAfter = true;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    $athleteValid = false;
                                                    $athleteValidAfter = false;
                                                    if (!$aClick) {
                                                        $_POST['athlete'] = 1;
                                                        $a_activ = 1;
                                                    }
                                                }
                                                if (!$athleteValid) {
                                                    $l = 1;
                                                    if (!$click) {
                                                        if ($a_first == 0) {
                                                            $_POST['athlete'] = 1;
                                                            $l = 0;
                                                        }
                                                    }
                                                }
                                            }
                                            if (in_array($row[15], $cfgResultsHighStayDecentralNotPassed)) {
                                                // find O (example: O, XO , XXO )
                                                $l = 0;
                                                // reset result counter
                                                $newAthl = false;
                                            } else {
                                                if (is_null($row[15])) {
                                                    $l = 0;
                                                    $newAthl = false;
                                                } else {
                                                    if (in_array($row[15], $cfgResultsHighStayDecentralEnd) && $_POST['athlete'] == $i && $skip) {
                                                        if ($athleteValidAfter && !$aClick) {
                                                            $_POST['athlete']++;
                                                        }
                                                        $newAthl = false;
                                                        $l = 1;
                                                    } elseif (in_array($row[15], $cfgResultsHighStayDecentralEnd) && $_POST['athlete'] == $i && !$skip && $p != $ph) {
                                                        $l = 1;
                                                    } else {
                                                        $l = 1;
                                                    }
                                                }
                                            }
                                        }
                                        if ($a != $row[4]) {
                                            if ($k == $ph) {
                                                $athleteValid = true;
                                                if ($starts != $count_ends) {
                                                    if (count($arr_info) == $starts) {
                                                        for ($r = $starts - 1; $r >= 0; $r--) {
                                                            if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                                $athleteValid = false;
                                                            } else {
                                                                $athleteValid = true;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    $athleteValid = false;
                                                    if (!$aClick) {
                                                        $_POST['athlete'] = 1;
                                                        $a_activ = 1;
                                                    }
                                                }
                                                $athleteValidAfter = true;
                                                for ($r = $starts - 1; $r >= 0; $r--) {
                                                    if ($r >= $_POST['athlete']) {
                                                        break;
                                                    }
                                                    if (in_array($arr_info[$r], $cfgResultsHighStayDecentralEnd)) {
                                                        $athleteValidAfter = false;
                                                    } else {
                                                        $athleteValidAfter = true;
                                                        break;
                                                    }
                                                }
                                                if (!$athleteValid) {
                                                    $l = 1;
                                                    if (!$click) {
                                                        if ($a_first == 0) {
                                                            $_POST['athlete'] = 1;
                                                            $l = 0;
                                                        }
                                                    }
                                                }
                                            }
                                            $a = $row[4];
                                            // keep athlete ID
                                            $info_keep = $row[15];
                                            // keep info
                                            $i++;
                                            // increment athlete counter
                                            $newAthl = true;
                                            if (in_array($row[15], $cfgResultsHighStayDecentralNotPassed)) {
                                                // find O (example: O, XO , XXO )
                                                $l = 0;
                                                // reset result counter
                                                $newAthl = false;
                                            } else {
                                                if (is_null($row[15])) {
                                                    $l = 0;
                                                    $newAthl = false;
                                                } else {
                                                    if (in_array($row[15], $cfgResultsHighStayDecentralEnd) && $_POST['athlete'] == $i && $skip && !$aClick) {
                                                        if ($starts != $count_ends) {
                                                            $_POST['athlete']++;
                                                        }
                                                        $newAthl = false;
                                                        $l = 1;
                                                    } elseif (in_array($row[15], $cfgResultsHighStayDecentralEnd) && $_POST['athlete'] == $i && !$skip && $p != $ph) {
                                                        $l = 1;
                                                    } else {
                                                        $l = 1;
                                                    }
                                                }
                                            }
                                            if ($a_activ == $i) {
                                                // active item
                                                $rowclass = 'active';
                                                if (isset($_POST['start'])) {
                                                    AA_setCurrAthlete($row[2], $row[4]);
                                                }
                                            } else {
                                                if ($row[5] % 2 == 0) {
                                                    // even row numer
                                                    $rowclass = 'even';
                                                } else {
                                                    // odd row number
                                                    $rowclass = 'odd';
                                                }
                                            }
                                            if ($rowclass == 'active') {
                                                ?>
                                <tr  id="athlete_<?php 
                                                echo $i;
                                                ?>
" class='active'>
                            <?php 
                                            } else {
                                                ?>
                                <tr id="athlete_<?php 
                                                echo $i;
                                                ?>
" class='<?php 
                                                echo $rowclass;
                                                ?>
'
                                    onclick='selectAthlete(<?php 
                                                echo $i;
                                                ?>
)'>
                            <?php 
                                            }
                                            ?>
                        <td class='forms_right'><?php 
                                            echo $row[5];
                                            ?>
</td>
                        <td class='forms_right'><?php 
                                            echo $row[7];
                                            /* start nbr */
                                            ?>
</td>
                        <td nowrap><?php 
                                            echo $row[8] . " " . $row[9];
                                            /* name */
                                            ?>
</td>
                        <td class='forms_ctr'><?php 
                                            echo AA_formatYearOfBirth($row[10]);
                                            ?>
</td>
                        <td><?php 
                                            echo $row[16] != '' && $row[16] != '-' ? $row[16] : '&nbsp;';
                                            ?>
</td>
                        <td nowrap><?php 
                                            echo $row[11];
                                            /* club */
                                            ?>
</td>
                               
                        <?php 
                                            if ($a_activ == $i) {
                                                ?>
                                    <form action='event_results.php' method='post'
                                        name='rank'>
                                    <td>
                                        <input type='hidden' name='arg' value='save_rank' />
                                        <input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
                                         <input type='hidden' name='singleRound' value='<?php 
                                                echo $singleRound;
                                                ?>
' />    
                                        <input type='hidden' name='athlete' value='<?php 
                                                echo $i + $focus;
                                                ?>
' />
                                        <input type='hidden' name='item' value='<?php 
                                                echo $row[4];
                                                ?>
' />                                           
                                        <input class='nbr' type='text' name='rank' maxlength='3'
                                            value='<?php 
                                                echo $row[6];
                                                ?>
' onchange='document.rank.submit()' />
                                    </td>
                                    </form>
                              
                                  <?php 
                                                if ($zaehler == 0) {
                                                    ?>
                                    
                                     <form action='event_results.php' method='post'
                                        name='remark_<?php 
                                                    echo $i;
                                                    ?>
'>
                                    <td>
                                        <input type='hidden' name='arg' value='save_remark' />
                                        <input type='hidden' name='round' value='<?php 
                                                    echo $round;
                                                    ?>
' />
                                         <input type='hidden' name='singleRound' value='<?php 
                                                    echo $singleRound;
                                                    ?>
' />    
                                        <input type='hidden' name='athlete' value='<?php 
                                                    echo $i + $focus;
                                                    ?>
' />
                                        <input type='hidden' name='item' value='<?php 
                                                    echo $row[4];
                                                    ?>
' />                                          
                                        <input type='hidden' name='xAthlete' value='<?php 
                                                    echo $row[18];
                                                    ?>
' />    
                                        <input class='textshort' type='text' name='remark' maxlength='5'
                                            value='<?php 
                                                    echo $row[17];
                                                    ?>
' onchange='document.remark_<?php 
                                                    echo $i;
                                                    ?>
.submit()' />
                                    </td>
                                    </form>  
                                    <?php 
                                                    $zaehler++;
                                                }
                                            } else {
                                                echo "<td>" . $row[6] . "</td>";
                                                echo "<td>" . $row[17] . "</td>";
                                            }
                                        }
                                        // ET new athlete
                                        $new_perf = '';
                                        if ($_POST['athlete'] == $i) {
                                            // only current athlet
                                            $item = '';
                                            $ph_perf = $ph - 1;
                                            $hiddenName = "hiddenHight_" . $ph_perf;
                                            if ($newHight) {
                                                $ph_perf += 1;
                                            }
                                            $hiddenName = "hiddenHight_" . $ph_perf;
                                            $new_perf = $arr_height[$ph_perf];
                                            $new_perf = new PerformanceAttempt($new_perf);
                                            $new_perf = $new_perf->getPerformance();
                                            // read all performances achieved in current heat and
                                            // better than last entered performance
                                            if (in_array($row[15], $cfgResultsHighStayDecentral)) {
                                                $new_info = $row[15];
                                                if (in_array($row[15], $cfgResultsHighStayDecentralEnd)) {
                                                    $new_info = '';
                                                } else {
                                                    $item = $row[13];
                                                }
                                            } else {
                                                $new_info = '';
                                            }
                                            if (is_null($row[14]) == false && empty($item)) {
                                                // next height
                                                ?>
                                <td nowrap>
                                    <?php 
                                                echo $row[15];
                                                ?>
                                </td>
                                <?php 
                                                if ($_POST['athlete'] == $a_activ) {
                                                    ?>
                                        <td>
                                        <?php 
                                                    $btn = new GUI_Button("event_results.php?arg=delete&round={$round}&item={$row['13']}&athlete={$i}", "del");
                                                    $btn->printButton();
                                                    ?>
                                        </td>
                                        <?php 
                                                } else {
                                                    ?>
                                        <td></td>  
                                        <?php 
                                                }
                                            }
                                            if ($l == 0) {
                                                // first item
                                                $find = strpos(strtoupper($row[15], 'O'));
                                                if ($row[15] == '-') {
                                                    if (!$skip) {
                                                        $l++;
                                                    }
                                                } elseif (!in_array($row[15], $cfgResultsHighStayDecentralNotPassed)) {
                                                    $l++;
                                                }
                                                $flagField = true;
                                                ?>
                            <form action='event_results.php' method='post'
                                        name='perf'>
                            <td nowrap colspan='2'> 
                                        <input type='hidden' name='arg' value='save_res' />
                                        <input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
                                         <input type='hidden' name='singleRound' value='<?php 
                                                echo $singleRound;
                                                ?>
' />    
                                        <input type='hidden' name='athlete' value='<?php 
                                                echo $i + $focus;
                                                ?>
' />
                                        <input type='hidden' name='start' value='<?php 
                                                echo $row[4];
                                                ?>
' />  
                                        <input type='hidden' name='xSerie' value='<?php 
                                                echo $row[2];
                                                ?>
' />                                        
                                        <input type='hidden' name='item' value='<?php 
                                                echo $item;
                                                ?>
' />
                                        <input class='perfheight' type='hidden' name='perf' maxlength='5'
                                            value='<?php 
                                                echo $new_perf;
                                                ?>
'
                                                 />
                                         <?php 
                                                foreach ($_POST as $key => $val) {
                                                    $arr_key = explode('_', $key);
                                                    $hiddenName = $arr_key[0] . "_" . $arr_key[1];
                                                    ?>
                                                 <input type='hidden' name='<?php 
                                                    echo $hiddenName;
                                                    ?>
' value='<?php 
                                                    echo $val;
                                                    ?>
' /> 
                                                 <?php 
                                                }
                                                ?>
         
                                        <input class='texttiny' type='text' name='attempts' maxlength='3' onfocus="this.value = '<?php 
                                                echo $new_info;
                                                ?>
'"  
                                            value='<?php 
                                                echo $new_info;
                                                ?>
' />
                                                
                                             <button type='button' name="butt" onclick="document.perf.submit()">ok</button> 
                            </td>
                            </form>      
                            
                                           <?php 
                                                $prev_info = '';
                                                echo "<td colspan='31'>&nbsp;";
                                                echo "</td>";
                                                echo "<td>";
                                                $btn->set("event_results.php?arg=del_start&item={$a}&round={$round}", $strDelete);
                                                $btn->printButton();
                                                echo "</td>";
                                            }
                                        } else {
                                            if (is_null($row[14]) == false) {
                                                // result entered
                                                $showNotValidRes = '';
                                                if ($row[14] < 0) {
                                                    $showNotValidRes = "({$row['14']})";
                                                }
                                                echo "<td colspan='2' nowrap>{$showNotValidRes} {$row['15']} </td>";
                                            }
                                        }
                                    }
                                    if ($a != 0) {
                                        if ($s == $s_keep || $s_keep == 1 || $info_keep == '-' && $ph == $k) {
                                            if (!$aClick) {
                                                $skip = true;
                                                $_POST['athlete']++;
                                            }
                                        } else {
                                            $skip = false;
                                        }
                                        if ($_POST['athlete'] == $i) {
                                            if (!$flagField && !$skip) {
                                                ?>
                            <form action='event_results.php' method='post'
                                        name='perf'>
                            <td nowrap colspan='2'> 
                                        <input type='hidden' name='arg' value='save_res' />
                                        <input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
                                         <input type='hidden' name='singleRound' value='<?php 
                                                echo $singleRound;
                                                ?>
' />    
                                        <input type='hidden' name='athlete' value='<?php 
                                                echo $i + $focus;
                                                ?>
' />
                                        <input type='hidden' name='start' value='<?php 
                                                echo $a;
                                                ?>
' />                                            
                                        <input type='hidden' name='item' value='<?php 
                                                echo $item;
                                                ?>
' />
                                        <input class='perfheight' type='hidden' name='perf' maxlength='5'
                                            value='<?php 
                                                echo $new_perf;
                                                ?>
'
                                                 />
                                                  <?php 
                                                foreach ($_POST as $key => $val) {
                                                    $arr_key = explode('_', $key);
                                                    $hiddenName = $arr_key[0] . "_" . $arr_key[1];
                                                    ?>
                                                 <input type='hidden' name='<?php 
                                                    echo $hiddenName;
                                                    ?>
' value='<?php 
                                                    echo $val;
                                                    ?>
' /> 
                                                 <?php 
                                                }
                                                ?>
         
                                        <input class='texttiny' type='text' name='attempts' maxlength='3' onfocus="this.value = '<?php 
                                                echo $new_info;
                                                ?>
'"   
                                            value='<?php 
                                                echo $new_info;
                                                ?>
' />
                                         <button type='button' name="butt" onclick="document.perf.submit()">ok</button>
                            </td>
                            </form> 
                            <?php 
                                                echo "<td colspan='15'>&nbsp;";
                                                echo "</td>";
                                                echo "<td>";
                                                $btn->set("event_results.php?arg=del_start&item={$a}&round={$round}", $strDelete);
                                                $btn->printButton();
                                                echo "</td>";
                                            }
                                        }
                                        echo "</tr>";
                                    }
                                    ?>
    
            
</table>
  
                 
            <?php 
                                    mysql_free_result($res);
                                }
                                // ET DB error
                            }
                        }
                    }
                }
            }
            ?>

<script type="text/javascript">
<!--
    var prog = "<?php 
            echo $prog_mode;
            ?>
";
  
   
    if (prog == 2) {   
           if(document.perf) { 
               document.perf.attempts.focus();                
               window.scrollBy(0,100);  
            }    
    }
    else {      
        if(document.perf) {
                    document.perf.perf.focus();
                    document.perf.perf.select();
                    window.scrollBy(0,100);
        }
         if(document.rank) {
            document.rank.rank.focus();
            document.rank.rank.select();
            window.scrollBy(0,100);
        }
    }  
//-->
</script>

</body>
</html>

<?php 
        } else {
            AA_printErrorMsg($strErrMergedRound);
        }
    }
    function AA_results_Track($round, $layout, $autoRank = '')
    {
        require './lib/cl_gui_button.lib.php';
        require './lib/cl_gui_dropdown.lib.php';
        require './lib/cl_gui_select.lib.php';
        require './config.inc.php';
        require './lib/common.lib.php';
        require './lib/heats.lib.php';
        require './lib/results.lib.php';
        require './lib/utils.lib.php';
        require './lib/timing.lib.php';
        $presets = AA_results_getPresets($round);
        // read GET/POST variables
        $relay = AA_checkRelay($presets['event']);
        // check, if this is a relay event
        $svm = AA_checkSVM(0, $round);
        // decide whether to show club or team name
        // $flagMain=AA_getMainRound($round);
        //   if ($flagMain) {
        //
        // terminate result processing
        //
        if ($_GET['arg'] == 'results_done') {
            $eval = AA_results_getEvaluationType($round);
            $combined = AA_checkCombined(0, $round);
            $eventType = AA_getEventTypes($round);
            mysql_query("\r\n\t\tLOCK TABLES\r\n\t\t\trundentyp READ\r\n\t\t\t, runde READ\r\n\t\t\t, serie READ\r\n\t\t\t, resultat READ\r\n\t\t\t, wettkampf READ\r\n\t\t\t, start WRITE\r\n\t\t\t, serienstart WRITE\r\n\t");
            if ($eval == $cfgEvalType[$strEvalTypeAll] || $eval == $cfgEvalType[$strEvalTypeHeat] && isset($eventType['club'])) {
                // eval all heats together
                $heatorder = "";
            } else {
                // default: rank results per heat
                $heatorder = "serie.xSerie, ";
            }
            $nextRound = AA_getNextRound($presets['event'], $round);
            // if this is a combined event, rank all rounds togheter
            $roundSQL = "";
            if ($combined) {
                $roundSQL = "WHERE serie.xRunde IN (";
                $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $presets['event']);
                while ($row_c = mysql_fetch_array($res_c)) {
                    $roundSQL .= $row_c[0] . ",";
                }
                $roundSQL = substr($roundSQL, 0, -1) . ")";
            } else {
                $roundSQL = "WHERE serie.xRunde = {$round}";
            }
            /*$result = mysql_query("
            		SELECT
            			resultat.Leistung
            			, serienstart.xSerienstart
            			, serienstart.xSerie
            			, serienstart.xStart
            			, serie.Wind
            		FROM
            			resultat
            			, serienstart
            			, serie
            		WHERE resultat.xSerienstart = serienstart.xSerienstart
            		
            		AND serienstart.xSerie = serie.xSerie
            		$roundSQL
            		ORDER BY
            			$heatorder
            			resultat.Leistung ASC
            	");  */
            $sql = "SELECT DISTINCT \r\n\t\t\t\t   resultat.Leistung, \r\n\t\t\t\t   serienstart.xSerienstart, \r\n\t\t\t\t   serienstart.xSerie, \r\n\t\t\t\t   serienstart.xStart, \r\n\t\t\t\t   serie.Wind \r\n\t\t\t  FROM resultat \r\n\t\t LEFT JOIN serienstart USING(xSerienstart) \r\n\t\t LEFT JOIN serie USING(xSerie) \r\n\t\t\t " . $roundSQL . " \r\n\t\t  ORDER BY " . $heatorder . "\r\n\t\t\t\t   resultat.Leistung ASC;";
            $result = mysql_query($sql);
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                $heat = 0;
                $perf = 0;
                $i = 0;
                $rank = 0;
                while ($row = mysql_fetch_row($result)) {
                    // check on codes < 0
                    if ($row[0] < 0) {
                        mysql_query("UPDATE serienstart SET" . " Rang = 0" . " WHERE xSerienstart = " . $row[1]);
                    } else {
                        if (!($eval == $cfgEvalType[$strEvalTypeHeat] && isset($eventType['club']))) {
                            if ($eval != $cfgEvalType[$strEvalTypeAll] && $heat != $row[2]) {
                                $i = 0;
                                // restart ranking   (not SVM with single heat)
                                $perf = 0;
                            }
                        }
                        $i++;
                        // increment ranking
                        if ($perf < $row[0]) {
                            // compare with previous performance
                            $rank = $i;
                            // next rank (only if not same performance)
                        }
                        mysql_query("UPDATE serienstart SET" . " Rang = " . $rank . " WHERE xSerienstart = " . $row[1]);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        // keep performance for information (heat seeding)
                        if ($nextRound > 0) {
                            mysql_query("\r\n\t\t\t\t\t\tUPDATE start SET\r\n\t\t\t\t\t\t\tstart.Bestleistung = {$row['0']}\r\n\t\t\t\t\t\tWHERE start.xStart = {$row['3']}\r\n\t\t\t\t\t");
                        }
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        $heat = $row[2];
                        // keep current heat ID
                        $perf = $row[0];
                        // keep current performance
                    }
                }
                mysql_free_result($result);
            }
            mysql_query("UNLOCK TABLES");
            AA_results_setNotStarted($round);
            // update athletes with no result
            AA_utils_changeRoundStatus($round, $cfgRoundStatus['results_done']);
            if (!empty($GLOBALS['AA_ERROR'])) {
                AA_printErrorMsg($GLOBALS['AA_ERROR']);
            }
            AA_results_resetQualification($round);
        }
        // ET terminate results
        //
        // Qualify athletes after ranks are set
        //
        if ($_GET['arg'] == 'results_done' || $_POST['arg'] == 'save_rank' || $_POST['arg'] == 'set_qual') {
            // read qualification criteria
            $qual_top = 0;
            $qual_perf = 0;
            $result = mysql_query("SELECT QualifikationSieger" . ", QualifikationLeistung" . " FROM runde" . " WHERE xRunde = " . $round);
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                if (($row = mysql_fetch_row($result)) == TRUE) {
                }
                $qual_top = $row[0];
                $qual_perf = $row[1];
                mysql_free_result($result);
            }
            // ET DB error
            // qualify top athletes for next round
            if ($qual_top > 0) {
                mysql_query("LOCK TABLES serie READ, serienstart WRITE");
                // get athletes by qualifying rank (random order if same rank)
                $result = mysql_query("SELECT serienstart.xSerienstart" . ", serienstart.xSerie" . ", serienstart.Rang" . " FROM serienstart" . ", serie" . " WHERE serienstart.Rang > 0" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round . " AND serienstart.Qualifikation = 0" . " ORDER BY serienstart.xSerie" . ", serienstart.Rang ASC" . ", RAND()");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    $h = 0;
                    unset($heats);
                    // clear array containing heats
                    while ($row = mysql_fetch_row($result)) {
                        if ($h != $row[1]) {
                            // new heat
                            if (count($starts) > 0) {
                                // count athletes
                                $heats[] = $starts;
                                // keep athletes per heat
                            }
                            unset($starts);
                            $c = 0;
                        }
                        $starts[$row[0]] = $row[2];
                        // keep athlete's rank
                        $h = $row[1];
                        // keep heat
                    }
                    $heats[] = $starts;
                    // keep remaining athletes
                    mysql_free_result($result);
                    foreach ($heats as $starts) {
                        $rankcount = array_count_values($starts);
                        // count athletes/rank
                        $q = 0;
                        foreach ($starts as $id => $rank) {
                            // check if more athletes per rank than qualifying spots
                            if ($rankcount[$rank] > $qual_top - $rank + 1) {
                                $qual = $cfgQualificationType['top_rand']['code'];
                            } else {
                                $qual = $cfgQualificationType['top']['code'];
                            }
                            if ($q < $qual_top) {
                                mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $qual . " WHERE xSerienstart = " . $id);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                                $q++;
                                // count nbr of qualified athletes
                            }
                        }
                    }
                    // END loop every heat
                }
                // ET DB error
                mysql_query("UNLOCK TABLES");
            }
            // ET top athletes
            // qualify top performing athletes for next round
            if ($qual_perf > 0) {
                mysql_query("LOCK TABLES resultat READ, serie READ, serienstart WRITE");
                // get remaining athletes by performance (random order if equal performance)
                /* other possible criteria to order equal performances:
                 * - ranking within heat (not implemented)
                 * - wind (not implemented)
                 */
                $result = mysql_query("SELECT serienstart.xSerienstart" . ", resultat.Leistung" . ", serienstart.Qualifikation" . " FROM resultat" . ", serienstart" . ", serie" . " WHERE resultat.xSerienstart = serienstart.xSerienstart" . " AND resultat.Leistung > 0" . " AND (serienstart.Qualifikation = 0 " . " OR serienstart.Qualifikation = " . $cfgQualificationType['waived']['code'] . ")" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round . " ORDER BY resultat.Leistung ASC" . ", RAND()");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    $i = 1;
                    $perf = 0;
                    $cWaived = 0;
                    while ($row = mysql_fetch_row($result)) {
                        // count waived qualifyings
                        if ($row[2] == $cfgQualificationType['waived']['code']) {
                            $cWaived++;
                            continue;
                        }
                        if ($i > $qual_perf) {
                            // terminate if enough top performers found
                            if ($perf != $row[1]) {
                                // last perf. worse than last qualified
                                $perf = 0;
                            }
                            break;
                        }
                        // if athletes waived on qualifying, set random code for next best athletes
                        $code = $cfgQualificationType['perf']['code'];
                        if ($i + $cWaived > $qual_perf) {
                            $code = $cfgQualificationType['perf_rand']['code'];
                        }
                        mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $code . " WHERE xSerienstart = " . $row[0]);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        $i++;
                        $perf = $row[1];
                        // keep performance
                    }
                    // reset performance if enough qualifing spots
                    if (mysql_num_rows($result) <= $qual_perf) {
                        $perf = 0;
                    }
                    mysql_free_result($result);
                    // Change qualification type to "perf_rand" for athletes with same
                    // performance as the 1st unqualified athlete
                    if ($perf != 0) {
                        $result = mysql_query("SELECT serienstart.xSerienstart" . " FROM resultat" . ", serienstart" . ", serie" . " WHERE resultat.xSerienstart = serienstart.xSerienstart" . " AND resultat.Leistung = " . $perf . " AND serienstart.Qualifikation > 0" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            while ($row = mysql_fetch_row($result)) {
                                mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $cfgQualificationType['perf_rand']['code'] . " WHERE xSerienstart = " . $row[0]);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                            mysql_free_result($result);
                        }
                    }
                    // ET unqualified athlete
                }
                // ET DB error qualified by performance
                mysql_query("UNLOCK TABLES");
            }
            // ET top performances
        }
        //
        // calculate ranking points if needed
        //
        if ($_GET['arg'] == 'results_done' || $_POST['arg'] == 'save_rank') {
            AA_utils_calcRankingPoints($round);
            // only for SVM with heat single --> set back the ranks per heat
            if ($eval == $cfgEvalType[$strEvalTypeHeat] && isset($eventType['club'])) {
                mysql_query("\r\n\t\tLOCK TABLES\r\n\t\t\trundentyp READ\r\n\t\t\t, runde READ\r\n\t\t\t, serie READ\r\n\t\t\t, resultat READ   \r\n\t\t\t, serienstart WRITE\r\n\t");
                // if this is a combined event, rank all rounds togheter
                $heatorder = "serie.xSerie, ";
                $roundSQL = "";
                if ($combined) {
                    $roundSQL = "AND serie.xRunde IN (";
                    $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $presets['event']);
                    while ($row_c = mysql_fetch_array($res_c)) {
                        $roundSQL .= $row_c[0] . ",";
                    }
                    $roundSQL = substr($roundSQL, 0, -1) . ")";
                } else {
                    $roundSQL = "AND serie.xRunde = {$round}";
                }
                $result = mysql_query("\r\n\t\tSELECT \r\n\t\t\tresultat.Leistung\r\n\t\t\t, serienstart.xSerienstart\r\n\t\t\t, serienstart.xSerie\r\n\t\t\t, serienstart.xStart\r\n\t\t\t, serie.Wind\r\n\t\t\t, serienstart.Rang\t\t\t\r\n\t\tFROM\r\n\t\t\tresultat\r\n\t\t\t, serienstart\r\n\t\t\t, serie\r\n\t\tWHERE resultat.xSerienstart = serienstart.xSerienstart\r\n\t\t\r\n\t\tAND serienstart.xSerie = serie.xSerie\r\n\t\t{$roundSQL}\r\n\t\tORDER BY\r\n\t\t\t{$heatorder}\r\n\t\t\tresultat.Leistung ASC\r\n\t");
                if (mysql_errno() > 0) {
                    // DB error
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    $heat = 0;
                    $perf = 0;
                    $i = 0;
                    $rank = 0;
                    while ($row = mysql_fetch_row($result)) {
                        // check on codes < 0
                        if ($row[0] < 0) {
                            mysql_query("UPDATE serienstart SET" . " Rang = 0" . " WHERE xSerienstart = " . $row[1]);
                        } else {
                            if ($eval != $cfgEvalType[$strEvalTypeAll] && $heat != $row[2]) {
                                $i = 0;
                                // restart ranking
                                $perf = 0;
                            }
                            if ($row[5] != 0) {
                                // rank
                                $i++;
                                // increment ranking
                                if ($perf < $row[0]) {
                                    // compare with previous performance
                                    $rank = $i;
                                    // next rank (only if not same performance)
                                }
                                mysql_query("UPDATE serienstart SET" . " Rang = " . $rank . " WHERE xSerienstart = " . $row[1]);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                            $heat = $row[2];
                            // keep current heat ID
                            $perf = $row[0];
                            // keep current performance
                        }
                    }
                    mysql_free_result($result);
                }
                mysql_query("UNLOCK TABLES");
            }
            // end:   only for SVM with heat single --> set back the ranks per heat
        }
        if ($autoRank) {
            // automatic ranking returns to event monitor
            return;
        }
        //
        // get results from timing system
        //  - save directly in database
        //
        if ($_GET['arg'] == "time_measurement") {
            AA_timing_getResultsManual($round);
        }
        //
        // print HTML page header
        //
        AA_results_printHeader($presets['category'], $presets['event'], $round);
        $mergedMain = AA_checkMainRound($round);
        if ($mergedMain != 1) {
            // read round data
            if ($round > 0) {
                $status = AA_getRoundStatus($round);
                // No action yet
                if ($status == $cfgRoundStatus['open'] || $status == $cfgRoundStatus['enrolement_done'] || $status == $cfgRoundStatus['heats_in_progress']) {
                    AA_printWarningMsg($strHeatsNotDone);
                } else {
                    if ($status == $cfgRoundStatus['enrolement_pending']) {
                        AA_printWarningMsg($strEnrolementNotDone);
                    } else {
                        if ($status >= $cfgRoundStatus['heats_done']) {
                            AA_heats_printNewStart($presets['event'], $round, "event_results.php");
                            $nextRound = AA_getNextRound($presets['event'], $round);
                            // show qualification form if another round follows
                            if ($nextRound > 0) {
                                $result = mysql_query("\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tQualifikationSieger\r\n\t\t\t\t\t, QualifikationLeistung\r\n\t\t\t\tFROM\r\n\t\t\t\t\trunde\r\n\t\t\t\tWHERE xRunde = {$round}\r\n\t\t\t");
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    if (($row = mysql_fetch_row($result)) == TRUE) {
                                    }
                                    ?>
<p/>
<table class='dialog'>
	<tr>
	<form action='event_results.php' method='post' name='qualification'>
		<td class='dialog'>
			<input type='hidden' name='arg' value='set_qual' />
			<input type='hidden' name='round' value='<?php 
                                    echo $round;
                                    ?>
' />
			<?php 
                                    echo $strQualification . " " . $strQualifyTop;
                                    ?>
</td>
		<td class='dialog'>
			<input class='nbr' name='qual_top' type='text' maxlength='4'
				value='<?php 
                                    echo $row[0];
                                    ?>
' /></td>
		<td class='dialog'>
			<?php 
                                    echo $strQualification . " " . $strQualifyPerformance;
                                    ?>
</td>
		<td class='dialog'>
			<input class='nbr' name='qual_perf' type='text' maxlength='4'
				value='<?php 
                                    echo $row[1];
                                    ?>
' /></td>
		<td>
			<button type='submit'>
				<?php 
                                    echo $strChange;
                                    ?>
			</button>
		</td>
	</form>
	</tr>
</table>
<p/>
<?php 
                                    $printed = TRUE;
                                    // qualification parameters printed
                                    // ET round found
                                    mysql_free_result($result);
                                }
                                // ET DB error
                            }
                            // ET next round
                            // check if round is final
                            $sql_r = "SELECT \r\n                    rt.Typ\r\n                FROM\r\n                    runde as r\r\n                    LEFT JOIN rundentyp as rt USING (xRundentyp)\r\n                WHERE\r\n                    r.xRunde=" . $round;
                            $res_r = mysql_query($sql_r);
                            if (mysql_errno() > 0) {
                                // DB error
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            }
                            $order = "ASC";
                            if (mysql_num_rows($res_r) == 1) {
                                $row_r = mysql_fetch_row($res_r);
                                if ($row_r[0] == 'F') {
                                    $order = "DESC";
                                }
                            }
                            // display all athletes
                            if ($relay == FALSE) {
                                // single event
                                $query = "SELECT r.Bahnen" . ", rt.Name" . ", rt.Typ" . ", s.xSerie" . ", s.Bezeichnung" . ", s.Wind" . ", s.Film" . ", an.Bezeichnung" . ", ss.xSerienstart" . ", ss.Position" . ", ss.Rang" . ", ss.Qualifikation" . ", a.Startnummer" . ", at.Name" . ", at.Vorname" . ", at.Jahrgang" . ", if('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo))" . ", LPAD(s.Bezeichnung,5,'0') as heatid" . ", s.Handgestoppt" . ", at.Land" . ", ss.Bemerkung" . ", at.xAthlet" . " FROM runde AS r" . ", serie AS s" . ", serienstart AS ss" . ", start AS st" . ", anmeldung AS a" . ", athlet AS at" . ", verein AS v" . " LEFT JOIN team AS t ON(a.xTeam = t.xTeam)" . " LEFT JOIN rundentyp AS rt" . " ON rt.xRundentyp = r.xRundentyp" . " LEFT JOIN anlage AS an" . " ON an.xAnlage = s.xAnlage" . " WHERE r.xRunde = " . $round . " AND s.xRunde = r.xRunde" . " AND ss.xSerie = s.xSerie" . " AND st.xStart = ss.xStart" . " AND a.xAnmeldung = st.xAnmeldung" . " AND at.xAthlet = a.xAthlet" . " AND v.xVerein = at.xVerein" . " ORDER BY heatid " . $order . ", ss.Position";
                            } else {
                                // relay event
                                $query = "SELECT r.Bahnen" . ", rt.Name" . ", rt.Typ" . ", s.xSerie" . ", s.Bezeichnung" . ", s.Wind" . ", s.Film" . ", an.Bezeichnung" . ", ss.xSerienstart" . ", ss.Position" . ", ss.Rang" . ", ss.Qualifikation" . ", sf.Name" . ", if('" . $svm . "', t.Name, v.Name)" . ", LPAD(s.Bezeichnung,5,'0') as heatid" . ", s.Handgestoppt" . ", ss.Bemerkung" . " FROM runde AS r" . ", serie AS s" . ", serienstart AS ss" . ", start AS st" . ", staffel AS sf" . ", verein AS v" . " LEFT JOIN team AS t ON(sf.xTeam = t.xTeam)" . " LEFT JOIN rundentyp AS rt" . " ON rt.xRundentyp = r.xRundentyp" . " LEFT JOIN anlage AS an" . " ON an.xAnlage = s.xAnlage" . " WHERE r.xRunde = " . $round . " AND s.xRunde = r.xRunde" . " AND ss.xSerie = s.xSerie" . " AND st.xStart = ss.xStart" . " AND sf.xStaffel = st.xStaffel" . " AND v.xVerein = sf.xVerein" . " ORDER BY heatid " . $order . ", ss.Position";
                            }
                            $result = mysql_query($query);
                            if (mysql_errno() > 0) {
                                // DB error
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            } else {
                                AA_results_printMenu($round, $status, $prog_mode, 'track');
                                // initialize variables
                                $h = 0;
                                // heat counter
                                $p = 0;
                                // position counter (to evaluate empty heats
                                $i = 0;
                                // input counter (an individual id is assigned to each
                                // input field, focus is then moved to the next input
                                // field by calling $i+1)
                                $rowclass = 'odd';
                                $tracks = 0;
                                $btn = new GUI_Button('', '');
                                // create button object
                                ?>
<p/>
<table class='dialog'>
<?php 
                                while ($row = mysql_fetch_row($result)) {
                                    $p++;
                                    // increment position counter
                                    /*
                                     *  Heat headerline
                                     */
                                    if ($h != $row[3]) {
                                        $tracks = $row[0];
                                        // keep nbr of planned tracks
                                        // fill previous heat with empty tracks
                                        if ($p > 1) {
                                            printEmptyTracks($p, $tracks, 5 + $c);
                                        }
                                        $h = $row[3];
                                        // keep heat ID
                                        $p = 1;
                                        // start with track one
                                        if (is_null($row[1])) {
                                            // only one round
                                            $title = "{$strFinalround}";
                                        } else {
                                            // more than one round
                                            $title = "{$row['1']}";
                                        }
                                        // increment colspan to include ranking and qualification
                                        $c = 0;
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            $c++;
                                            if ($nextRound > 0) {
                                                $c++;
                                            }
                                        }
                                        ?>
	<tr>
		<form action='event_results.php#heat_<?php 
                                        echo $row[4];
                                        ?>
' method='post'
			name='heat_id_<?php 
                                        echo $h;
                                        ?>
'>

		<th class='dialog' colspan='3'>
			<?php 
                                        echo $title;
                                        ?>
			<input type='hidden' name='arg' value='change_heat_name' />
			<input type='hidden' name='round' value='<?php 
                                        echo $round;
                                        ?>
' />
			<input type='hidden' name='item' value='<?php 
                                        echo $row[3];
                                        ?>
' />
			<input class='nbr' type='text' name='id' maxlength='2'
				value='<?php 
                                        echo $row[4];
                                        ?>
'
				onChange='document.heat_id_<?php 
                                        echo $h;
                                        ?>
.submit()' />
				<a name='heat_<?php 
                                        echo $row[4];
                                        ?>
' />
		</th>
		</form>
<?php 
                                        if ($status != $cfgRoundStatus['results_done']) {
                                            ?>
		<form action='controller.php' method='post'
			name='filmheat_<?php 
                                            echo $row[4];
                                            ?>
' target='controller'>
		<th class='dialog' colspan='2'>
			<?php 
                                            echo $strFilm;
                                            ?>
			<input type='hidden' name='act' value='saveFilm' />
			<input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
			<input type='hidden' name='item' value='<?php 
                                            echo $row[3];
                                            ?>
' />
			<input class='nbr' type='text' name='film' id='in_<?php 
                                            echo $i;
                                            ?>
'
				maxlength='3' value='<?php 
                                            echo $row[6];
                                            ?>
'
				onChange="submitForm(document.filmheat_<?php 
                                            echo $row[4];
                                            ?>
, 'in_<?php 
                                            echo $i + 1;
                                            ?>
')" />
		</th>
		</form>
<?php 
                                            $i++;
                                            // next element
                                        } else {
                                            // results done
                                            ?>
		<th class='dialog' colspan='2'>
			<?php 
                                            echo $strFilm . " " . $row[6];
                                            ?>
		</th>
<?php 
                                        }
                                        // track discipline with wind
                                        if ($layout == $cfgDisciplineType[$strDiscTypeTrack]) {
                                            if ($status != $cfgRoundStatus['results_done']) {
                                                ?>
		<form action='controller.php' method='post'
			name='windheat_<?php 
                                                echo $row[4];
                                                ?>
' target='controller'>
		<th class='dialog' colspan='<?php 
                                                echo 1 + $c;
                                                ?>
'>
			<?php 
                                                echo $strWind;
                                                ?>
			<input type='hidden' name='act' value='saveWind' />
			<input type='hidden' name='obj' value='windheat_<?php 
                                                echo $row[4];
                                                ?>
' />
			<input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
			<input type='hidden' name='item' value='<?php 
                                                echo $row[3];
                                                ?>
' />
			<input class='nbr' type='text' name='wind'  id='in_<?php 
                                                echo $i;
                                                ?>
'
				maxlength='5' value='<?php 
                                                echo $row[5];
                                                ?>
'
				onChange="submitForm(document.windheat_<?php 
                                                echo $row[4];
                                                ?>
, 'in_<?php 
                                                echo $i + 1;
                                                ?>
')" />
		</th>
		</form>
<?php 
                                                $i++;
                                                // next element
                                            } else {
                                                // results done
                                                ?>
		<th class='dialog' colspan='2'>
			<?php 
                                                echo $strWind . " " . $row[5];
                                                ?>
		</th>
<?php 
                                            }
                                        } else {
                                            ?>
		<th class='dialog' colspan='<?php 
                                            echo 1 + $c;
                                            ?>
' />
<?php 
                                        }
                                        // ET track discipline with wind
                                        // can set "hand taken time"
                                        if ($row[18] == 1 && $relay == false) {
                                            $handstopped = "checked";
                                        } elseif ($row[15] == 1 && $relay == true) {
                                            $handstopped = "checked";
                                        } else {
                                            $handstopped = "";
                                        }
                                        if ($status != $cfgRoundStatus['results_done']) {
                                            ?>
		<form action='controller.php' method='post'
			name='handstopped_<?php 
                                            echo $row[4];
                                            ?>
' target='controller'>
		<th class='dialog'><?php 
                                            echo $strHandStopped;
                                            ?>
 
			<input type='hidden' name='act' value='saveHandStopped' />
			<input type='hidden' name='obj' value='handstopped_<?php 
                                            echo $row[4];
                                            ?>
' />
			<input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
			<input type='hidden' name='item' value='<?php 
                                            echo $row[3];
                                            ?>
' />
			<input type="checkbox" name="handstopped" id='in_<?php 
                                            echo $i;
                                            ?>
'
				onChange="submitForm(document.handstopped_<?php 
                                            echo $row[4];
                                            ?>
, 'in_<?php 
                                            echo $i + 1;
                                            ?>
')"
				<?php 
                                            echo $handstopped;
                                            ?>
 >
		</th>
		</form>
<?php 
                                            $i++;
                                            // next element
                                        } else {
                                            ?>
		<th class='dialog'><?php 
                                            echo $strHandStopped;
                                            ?>
			<input type="checkbox" name="handstopped" <?php 
                                            echo $handstopped;
                                            ?>
 disabled>
		</th>
<?php 
                                        }
                                        ?>
	</tr>
<?php 
                                        /*
                                         *  Column header
                                         */
                                        if ($relay == FALSE) {
                                            // athlete display
                                            ?>
	<tr>
		<th class='dialog'><?php 
                                            echo $strPositionShort;
                                            ?>
</th>
		<th class='dialog' colspan='2'><?php 
                                            echo $strAthlete;
                                            ?>
</th>
		<th class='dialog'><?php 
                                            echo $strYearShort;
                                            ?>
</th>
		<th class='dialog'><?php 
                                            echo $strCountry;
                                            ?>
</th>
		<th class='dialog'><?php 
                                            if ($svm) {
                                                echo $strTeam;
                                            } else {
                                                echo $strClub;
                                            }
                                            ?>
</th>
		<th class='dialog'><?php 
                                            echo $strPerformance;
                                            ?>
</th>
        
<?php 
                                        } else {
                                            // relay display
                                            ?>
	<tr>
		<th class='dialog'><?php 
                                            echo $strPositionShort;
                                            ?>
</th>
		<th class='dialog'><?php 
                                            echo $strRelay;
                                            ?>
</th>
		<th class='dialog'><?php 
                                            if ($svm) {
                                                echo $strTeam;
                                            } else {
                                                echo $strClub;
                                            }
                                            ?>
</th>
		<th class='dialog'><?php 
                                            echo $strPerformance;
                                            ?>
</th>
       
<?php 
                                        }
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            ?>
		<th class='dialog'><?php 
                                            echo $strRank;
                                            ?>
</th>
<?php 
                                            if ($nextRound > 0) {
                                                ?>
		<th class='dialog'><?php 
                                                echo $strQualification;
                                                ?>
</th>
<?php 
                                            }
                                        }
                                        ?>
<th class='dialog'><?php 
                                        echo $strResultRemark;
                                        ?>
</th>     
	</tr>
<?php 
                                    }
                                    // ET new heat
                                    /*
                                     * Empty tracks
                                     */
                                    if ($layout == $cfgDisciplineType[$strDiscTypeTrack] || $layout == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $layout == $cfgDisciplineType[$strDiscTypeRelay]) {
                                        // current track and athlete's position not identical
                                        if ($p < $row[9]) {
                                            $p = printEmptyTracks($p, $row[9] - 1, 5 + $c);
                                        }
                                    }
                                    // ET empty tracks
                                    /*
                                     * Athlete data lines
                                     */
                                    $p = $row[9];
                                    // keep position
                                    if ($p % 2 == 0) {
                                        // even row numer
                                        $rowclass = 'even';
                                    } else {
                                        // odd row number
                                        $rowclass = 'odd';
                                    }
                                    if ($relay == FALSE) {
                                        ?>
	<tr class='<?php 
                                        echo $rowclass;
                                        ?>
'>
		<td class='forms_right'><?php 
                                        echo $row[9];
                                        /* position */
                                        ?>
</td>
		<td class='forms_right'><?php 
                                        echo $row[12];
                                        /* start nbr */
                                        ?>
</td>
		<td><?php 
                                        echo $row[13] . " " . $row[14];
                                        /* name */
                                        ?>
</td>
		<td class='forms_ctr'><?php 
                                        echo AA_formatYearOfBirth($row[15]);
                                        ?>
</td>
		<td><?php 
                                        echo $row[19] != '' && $row[19] != '-' ? $row[19] : '&nbsp;';
                                        ?>
</td>
		<td><?php 
                                        echo $row[16];
                                        /* club */
                                        ?>
</td>
      
<?php 
                                    } else {
                                        // relay
                                        ?>
	<tr class='<?php 
                                        echo $rowclass;
                                        ?>
'>
		<td class='forms_right'><?php 
                                        echo $row[9];
                                        /* position */
                                        ?>
</td>
		<td><?php 
                                        echo $row[12];
                                        /* relay name */
                                        ?>
</td>
		<td><?php 
                                        echo $row[13];
                                        /* club */
                                        ?>
</td>
<?php 
                                    }
                                    $sql = "SELECT rs.xResultat, \r\n\t\t\t\t\t\t\t   rs.Leistung, \r\n\t\t\t\t\t\t\t   rs.Info, \r\n\t\t\t\t\t\t\t   d.Strecke \r\n\t\t\t\t\t\t  FROM resultat AS rs \r\n\t\t\t\t\t LEFT JOIN serienstart AS ss USING(xSerienstart) \r\n\t\t\t\t\t LEFT JOIN serie AS se USING(xSerie) \r\n\t\t\t\t\t LEFT JOIN runde AS ru USING(xRunde) \r\n\t\t\t\t\t LEFT JOIN wettkampf AS w USING(xWettkampf) \r\n\t\t\t\t\t LEFT JOIN disziplin AS d USING(xDisziplin) \r\n\t\t\t\t\t\t WHERE rs.xSerienstart = " . $row[8] . " \r\n\t\t\t\t\t  ORDER BY rs.Leistung ASC;";
                                    $res = mysql_query($sql);
                                    if (mysql_errno() > 0) {
                                        // DB error
                                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                    } else {
                                        $perf = '';
                                        $resrow = mysql_fetch_array($res);
                                        if ($resrow != NULL) {
                                            // result found
                                            /*$secflag = false;
                                            		if(substr($resrow[1],0,2) >= 60){
                                            			$secflag = true;
                                            		}*/
                                            $secflag = intval($resrow['Strecke']) <= 400;
                                            $perf = AA_formatResultTime($resrow[1], false, $secflag);
                                        }
                                        if ($status != $cfgRoundStatus['results_done']) {
                                            ?>
		<form action='controller.php' method='post'
			name='perf_<?php 
                                            echo $i;
                                            ?>
' target='controller'>
		<td>
			<input type='hidden' name='act' value='saveResult' />
			<input type='hidden' name='obj' value='perf_<?php 
                                            echo $i;
                                            ?>
' />
			<input type='hidden' name='type' value='<?php 
                                            echo $layout;
                                            ?>
' />
			<input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
			<input type='hidden' name='start' value='<?php 
                                            echo $row[8];
                                            ?>
' />
			<input type='hidden' name='item' value='<?php 
                                            echo $resrow[0];
                                            ?>
' />
			<input class='perftime' type='text' name='perf' id='in_<?php 
                                            echo $i;
                                            ?>
'
				maxlength='12' value='<?php 
                                            echo $perf;
                                            ?>
'
				onChange="submitForm(document.perf_<?php 
                                            echo $i;
                                            ?>
, 'in_<?php 
                                            echo $i + 1;
                                            ?>
')" />
		</td>
		</form>
        
        <form action='controller.php' method='post'
            name='remark_<?php 
                                            echo $i;
                                            ?>
' target='controller'>
        <td>
            <input type='hidden' name='act' value='saveResult' />
            <input type='hidden' name='obj' value='perf_<?php 
                                            echo $i;
                                            ?>
' />
            <input type='hidden' name='type' value='<?php 
                                            echo $layout;
                                            ?>
' />
            <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
            <input type='hidden' name='start' value='<?php 
                                            echo $row[8];
                                            ?>
' />
            <input type='hidden' name='item' value='<?php 
                                            echo $resrow[0];
                                            ?>
' />
            <input type='hidden' name='xAthlete' value='<?php 
                                            echo $row[21];
                                            ?>
' />   
            <input class='textshort' type='text' name='remark' id='in_<?php 
                                            echo $i;
                                            ?>
'
                maxlength='5' value='<?php 
                                            if ($relay) {
                                                echo $row[16];
                                            } else {
                                                echo $row[20];
                                            }
                                            ?>
'
                onChange="submitForm(document.remark_<?php 
                                            echo $i;
                                            ?>
, 'in_<?php 
                                            echo $i + 1;
                                            ?>
')" />
        </td>
        </form>
        
       
<?php 
                                            $i++;
                                            // next element
                                        } else {
                                            // results done
                                            ?>
		<td class='forms_right'><?php 
                                            echo $perf;
                                            ?>
</td>
<?php 
                                        }
                                        mysql_free_result($res);
                                        if ($status == $cfgRoundStatus['results_done']) {
                                            if ($row[10] > 0) {
                                                ?>
		<form action='event_results.php' method='post'
			name='rank_<?php 
                                                echo $i;
                                                ?>
'>
		<td>
			<input type='hidden' name='arg' value='save_rank' />
			<input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
			<input type='hidden' name='focus' value='rank_<?php 
                                                echo $i;
                                                ?>
' />
			<input type='hidden' name='item' value='<?php 
                                                echo $row[8];
                                                ?>
' />
			<input class='nbr' type='text' name='rank' maxlength='3'
				value='<?php 
                                                echo $row[10];
                                                ?>
'
				onChange='document.rank_<?php 
                                                echo $i;
                                                ?>
.submit()' />
		</td>
		</form>     
        
       
<?php 
                                                $i++;
                                                // next element
                                                if ($nextRound > 0) {
                                                    ?>
		<form action='event_results.php' method='post'
			name='qual_<?php 
                                                    echo $i;
                                                    ?>
'>
		<td>
			<input type='hidden' name='arg' value='change_qual' />
			<input type='hidden' name='round' value='<?php 
                                                    echo $round;
                                                    ?>
' />
			<input type='hidden' name='focus' value='qual_<?php 
                                                    echo $i;
                                                    ?>
' />
			<input type='hidden' name='item' value='<?php 
                                                    echo $row[8];
                                                    ?>
' />
			<input type='hidden' name='oldqual' value='<?php 
                                                    echo $row[11];
                                                    ?>
' />
			<input type='hidden' name='heat' value='<?php 
                                                    echo $row[3];
                                                    ?>
' />
<?php 
                                                    $dropdown = new GUI_Select('qual', 1, "document.qual_{$i}.submit()");
                                                    $dropdown->addOptionNone();
                                                    foreach ($cfgQualificationType as $type) {
                                                        $dropdown->addOption($type['text'], $type['code']);
                                                        if ($type['code'] == $row[11]) {
                                                            $dropdown->selectOption($type['code']);
                                                        }
                                                    }
                                                    $dropdown->printList();
                                                    ?>
		</td>
		</form>
<?php 
                                                    $i++;
                                                    // next element
                                                }
                                                // qualification info
                                            } else {
                                                // no rank
                                                ?>
                        <td /> 
                        
                        
<?php 
                                            }
                                            // ET no rank
                                            ?>
                        
                     <td class='perftime'><?php 
                                            if ($relay) {
                                                echo $row[16];
                                            } else {
                                                echo $row[20];
                                            }
                                            ?>
</td>      
<?php 
                                        }
                                        // ET 'results_done'
                                        ?>
		<td>
<?php 
                                        $btn->set("event_results.php?arg=del_start&item={$row['8']}&round={$round}", $strDelete);
                                        $btn->printButton();
                                        ?>
		</td>
<?php 
                                    }
                                    // ET DB error
                                }
                                // Fill last heat with empty tracks for disciplines run in
                                // individual tracks
                                if ($layout == $cfgDisciplineType[$strDiscTypeTrack] || $layout == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $layout == $cfgDisciplineType[$strDiscTypeRelay]) {
                                    if ($p > 0) {
                                        // heats set up
                                        $p++;
                                        printEmptyTracks($p, $tracks, 5 + $c);
                                    }
                                }
                                // ET track disciplines
                                ?>
</table>
<?php 
                                mysql_free_result($result);
                            }
                            // ET DB error
                        }
                    }
                }
            }
            // ET round selected
            if (!empty($presets['focus'])) {
                ?>

<script type="text/javascript">
<!--
	if(<?php 
                echo $presets['focus'];
                ?>
.rank) {
		<?php 
                echo $presets['focus'];
                ?>
.rank.focus();
		<?php 
                echo $presets['focus'];
                ?>
.rank.select();
		window.scrollBy(0,200);
	}
	else if(<?php 
                echo $presets['focus'];
                ?>
.qual) {
		<?php 
                echo $presets['focus'];
                ?>
.qual.focus();
		window.scrollBy(0,200);
	}
//-->
</script>
<?php 
            }
            ?>
</body>
</html>
<?php 
        } else {
            AA_printErrorMsg($strErrMergedRound);
        }
    }
Beispiel #3
0
    function AA_results_Tech($round, $layout)
    {
        require './lib/cl_gui_button.lib.php';
        require './config.inc.php';
        require './lib/common.lib.php';
        require './lib/heats.lib.php';
        require './lib/results.lib.php';
        require './lib/utils.lib.php';
        require './lib/cl_wind.lib.php';
        $presets = AA_results_getPresets($round);
        // read GET/POST variables
        $nextRound = AA_getNextRound($presets['event'], $round);
        $svm = AA_checkSVM(0, $round);
        // decide whether to show club or team name
        $prog_mode = AA_results_getProgramMode();
        //
        // terminate result processing
        //
        if ($_GET['arg'] == 'results_done' || $prog_mode == 2 && $_GET['arg'] != 'change_results' && $_GET['arg'] != 'del_results') {
            $eval = AA_results_getEvaluationType($round);
            $combined = AA_checkCombined(0, $round);
            mysql_query("LOCK TABLES r READ, s READ, ss READ, runde READ");
            // if this is a combined event, rank all rounds togheter
            $roundSQL = "";
            $roundSQL2 = "";
            if ($combined) {
                $roundSQL = " s.xRunde IN (";
                $roundSQL2 = " s.xRunde IN (";
                $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $presets['event']);
                while ($row_c = mysql_fetch_array($res_c)) {
                    $roundSQL .= $row_c[0] . ",";
                    $roundSQL2 .= $row_c[0] . ",";
                }
                $roundSQL = substr($roundSQL, 0, -1) . ")";
                $roundSQL2 = substr($roundSQL2, 0, -1) . ")";
            } else {
                $roundSQL = " s.xRunde = {$round}";
                $roundSQL2 = " s.xRunde = {$round}";
            }
            // number of athletes
            $sql = "SELECT \r\n                    ss.xSerienstart  \r\n             FROM \r\n                    runde AS r\r\n                    LEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n                    LEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n                    LEFT JOIN start AS st ON (st.xStart = ss.xStart)\r\n                    LEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n                    LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n             WHERE r.xRunde = " . $round . "\r\n                   ";
            $res = mysql_query($sql);
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                $count_athlete = mysql_num_rows($res);
            }
            // evaluate max. nbr of results entered
            $r = 0;
            if ($prog_mode == 2) {
                // create array for calculate field focus
                $sql_r = "SELECT                                      \r\n                ru.Versuche, \r\n                LPAD(s.Bezeichnung,5,'0') as heatid,  \r\n                if (ss.Position2 > 0, if (ss.Position3 > 0, ss.Position3, ss.Position2) , ss.Position ) as posOrder \r\n                , ss.Position\r\n                , ss.Position2\r\n                , ss.Position3 \r\n                , ss.xSerienstart\r\n                , ss.Rang\r\n                , s.MaxAthlet\r\n                , s.xSerie \r\n                , r.Leistung \r\n          FROM \r\n                resultat AS r\r\n                LEFT JOIN serienstart AS ss ON (r.xSerienstart = ss.xSerienstart)\r\n                LEFT JOIN serie AS s ON (ss.xSerie = s.xSerie )\r\n                LEFT JOIN runde AS ru ON (s.xRunde = ru.xRunde) \r\n          WHERE " . $roundSQL2 . "  \r\n          ORDER BY posOrder, r.xResultat ";
                $result_r = mysql_query($sql_r);
                $heatStart = '';
                $arr_perfAthlete = array();
                $arr_perfAthleteValids = array();
                $c = 0;
                $h = 0;
                $pos2 = 0;
                // calculate attempts of athletes
                while ($row_r = mysql_fetch_row($result_r)) {
                    if ($heatStart != $row_r[6]) {
                        // new heat start
                        if (!empty($heatStart)) {
                            $arr_perfAthlete[$h] = $c;
                            if ($c > 0) {
                                $arr_perfAthleteValids[$h] = $c;
                            }
                            $h++;
                            if ($h >= $row_r[8] && $row_r[4] > 0) {
                                // maxAthlete reached by second/third Position
                                break;
                            }
                        }
                        $c = 0;
                        if ($row_r[10] > 0 || $row_r[10] < $cfgInvalidResult['DSQ']['code']) {
                            $c++;
                        } elseif ($row_r[10] == $cfgInvalidResult['DNS']['code']) {
                            $c = $cfgInvalidResult['DNS']['code'];
                        } elseif ($row_r[10] == $cfgInvalidResult['DNF']['code']) {
                            $c = $cfgInvalidResult['DNF']['code'];
                        } elseif ($row_r[10] == $cfgInvalidResult['DSQ']['code']) {
                            $c = $cfgInvalidResult['DSQ']['code'];
                        }
                    } else {
                        if ($row_r[10] > 0 || $row_r[10] < $cfgInvalidResult['DSQ']['code']) {
                            $c++;
                        } elseif ($row_r[10] == $cfgInvalidResult['DNS']['code']) {
                            $c = $cfgInvalidResult['DNS']['code'];
                        } elseif ($row_r[10] == $cfgInvalidResult['DNF']['code']) {
                            $c = $cfgInvalidResult['DNF']['code'];
                        } elseif ($row_r[10] == $cfgInvalidResult['DSQ']['code']) {
                            $c = $cfgInvalidResult['DSQ']['code'];
                        }
                    }
                    $heatStart = $row_r[6];
                    $maxAthlete = $row_r[8];
                    $pos2 = $row_r[4];
                }
                // last athlete
                if ($h >= $maxAthlete && $pos2 > 0) {
                } else {
                    $arr_perfAthlete[$h] = $c;
                    if ($c > 0) {
                        $arr_perfAthleteValids[$h] = $c;
                    }
                }
                $p1 = 0;
                $p2 = 0;
                //calculate doing new position
                foreach ($arr_perfAthlete as $key => $val) {
                    if ($val == 3 || $val < 0) {
                        $p1++;
                    } elseif ($val == 5 || $val < 0) {
                        $p2++;
                    }
                }
                if (count($arr_perfAthlete) == $p1) {
                    AA_rankingForNewPosition($round, 2);
                    AA_newPosition($round, 2);
                } elseif (count($arr_perfAthlete) == $p2) {
                    AA_rankingForNewPosition($round, 3);
                    AA_newPosition($round, 3);
                }
                $sql = "SELECT \r\n                COUNT(*),                  \r\n                ru.Versuche, \r\n                LPAD(s.Bezeichnung,5,'0') as heatid,  \r\n                if (ss.Position2 > 0, if (ss.Position3 > 0, ss.Position3, ss.Position2) , ss.Position ) as posOrder \r\n                , ss.Position\r\n                , ss.Position2\r\n                , ss.Position3 \r\n                , ss.xSerienstart\r\n                , ss.Rang\r\n                , s.MaxAthlet\r\n                , s.xSerie \r\n                , r.Leistung\r\n                \r\n          FROM \r\n                resultat AS r\r\n                LEFT JOIN serienstart AS ss ON (r.xSerienstart = ss.xSerienstart)\r\n                LEFT JOIN serie AS s ON (ss.xSerie = s.xSerie )\r\n                LEFT JOIN runde AS ru ON (s.xRunde = ru.xRunde) \r\n          WHERE " . $roundSQL2 . "                       \r\n          GROUP BY r.xSerienstart\r\n          ORDER BY posOrder ";
                $result = mysql_query($sql);
            } else {
                $result = mysql_query("SELECT COUNT(*), ru.Versuche" . " FROM resultat AS r" . " LEFT JOIN serienstart AS ss ON (r.xSerienstart = ss.xSerienstart)" . " LEFT JOIN serie AS s ON (ss.xSerie = s.xSerie)" . " LEFT JOIN runde AS ru ON (s.xRunde = ru.xRunde)" . " WHERE " . " {$roundSQL2} " . " GROUP BY r.xSerienstart" . " ORDER BY 1 DESC");
            }
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                if ($prog_mode == 2) {
                    // decentral with ranking
                    $z = 0;
                    $pass = 0;
                    $arr_attAthlete = array();
                    $maxAthlete = 0;
                    while ($row = mysql_fetch_row($result)) {
                        if ($z == 0) {
                            // first row
                            $maxatt = $row[1];
                            $maxAthlete = $row[9];
                            $xSerie = $row[10];
                        }
                        if ($row[11] != $cfgInvalidResult['DNS']['code']) {
                            $arr_attAthlete[] = $row[0];
                        }
                        $keep_rank = $row[8];
                        $z++;
                    }
                    if ($count_athlete < $maxAthlete) {
                        $maxAthlete = $count_athlete;
                        // update max athlete in serie
                        AA_setMaxAthlete($xSerie, $maxAthlete);
                    }
                    $maxAthleteAtt = max($arr_attAthlete);
                    $minAthleteAtt = min($arr_attAthlete);
                    $onlyMaxAthlete = false;
                    if ($count_athlete > $cfgMaxAthlete) {
                        if ($maxAthleteAtt == $minAthleteAtt && $minAthleteAtt == $cfgAfterAttempts1) {
                            $onlyMaxAthlete = true;
                        } elseif ($maxAthleteAtt > $cfgAfterAttempts1) {
                            $onlyMaxAthlete = true;
                        }
                    }
                    if ($onlyMaxAthlete && $count_athlete > $cfgMaxAthlete) {
                        $c = 0;
                        $arr_attAthlete_new = array();
                        foreach ($arr_attAthlete as $key => $val) {
                            $c++;
                            $arr_attAthlete_new[] = $val;
                            if ($c >= $maxAthlete) {
                                break;
                            }
                        }
                        $arr_attAthlete = $arr_attAthlete_new;
                        $maxAthleteAtt = max($arr_attAthlete);
                        $minAthleteAtt = min($arr_attAthlete);
                    }
                    $r = $maxAthleteAtt;
                    $first_row = false;
                    $maxAthleteAtt = max($arr_perfAthleteValids);
                    $minAthleteAtt = min($arr_perfAthleteValids);
                    if ($maxAthleteAtt == $cfgAfterAttempts1 && $maxAthleteAtt == $minAthleteAtt) {
                        $pass = 2;
                    } elseif ($maxAthleteAtt == $cfgAfterAttempts2 && $maxAthleteAtt == $minAthleteAtt) {
                        $pass = 3;
                    } elseif ($maxAthleteAtt > $cfgAfterAttempts1 && $maxAthleteAtt < $cfgAfterAttempts2 + 1) {
                        $pass = 2;
                    } elseif ($maxAthleteAtt == $cfgAfterAttempts2 + 1) {
                        $pass = 3;
                    } elseif ($maxAthleteAtt == $minAthleteAtt && $z == $count_athlete) {
                        $first_row = true;
                        $maxAthleteAtt++;
                    }
                    $fieldFocus = 1;
                } else {
                    $row = mysql_fetch_row($result);
                    $r = $row[0];
                }
                mysql_free_result($result);
            }
            $minPerfAthl = min($arr_perfAthleteValids);
            $maxPerfAthl = max($arr_perfAthleteValids);
            $keep_val = '';
            $keep_key = '';
            foreach ($arr_perfAthlete as $key => $val) {
                if (empty($keep_val) && !empty($val)) {
                    $fieldFocus = $maxatt + 1 + $maxPerfAthl;
                }
                $keep_key = $key;
                if ($keep_val > $val) {
                    if ($val == $cfgInvalidResult['DNS']['code'] || $val == $cfgInvalidResult['DNF']['code'] || $val == $cfgInvalidResult['DSQ']['code']) {
                        continue;
                    }
                    $fieldFocus = $key * ($maxatt + 1) + $maxPerfAthl;
                    break;
                }
                $keep_val = $val;
            }
            if ($pos2 == 0) {
                if ($count_athlete > count($arr_perfAthlete)) {
                    $fieldFocus = ($keep_key + 1) * ($maxatt + 1) + $maxPerfAthl;
                } elseif ($count_athlete == count($arr_perfAthlete) && $minPerfAthl == $maxPerfAthl) {
                    $fieldFocus = $maxPerfAthl + 1;
                }
            } else {
                if ($minPerfAthl == $maxPerfAthl) {
                    $fieldFocus = $maxPerfAthl + 1;
                }
            }
            if ($r > 0) {
                mysql_query("DROP TABLE IF EXISTS tempresult");
                // temporary table
                if (mysql_errno() > 0) {
                    // DB error
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    mysql_query("\r\n                LOCK TABLES\r\n                    resultat READ\r\n                    , serie READ\r\n                    , wettkampf READ\r\n                    , serienstart WRITE\r\n                    , tempresult WRITE\r\n            ");
                    // Set up a temporary table to hold all results for ranking.
                    // The number of result columns varies according to the maximum
                    // number of results per athlete.
                    $qry = "\r\n                CREATE TABLE tempresult (\r\n                    xSerienstart int(11)\r\n                    , xSerie int(11)";
                    for ($i = 1; $i <= $r; $i++) {
                        $qry = $qry . ", Res" . $i . " int(9) default '0'";
                        $qry = $qry . ", Wind" . $i . " char(5) default '0'";
                    }
                    $qry = $qry . ") TYPE=HEAP";
                    mysql_query($qry);
                    // create temporary table
                    if (mysql_errno() > 0) {
                        // DB error
                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                    } else {
                        // reset rank to 0  first
                        $sql = " SELECT\r\n                        r.Leistung\r\n                        , r.Info\r\n                        , ss.xSerienstart\r\n                        , ss.xSerie\r\n                    FROM\r\n                        resultat as r\r\n                        LEFT JOIN serienstart as ss ON (r.xSerienstart = ss.xSerienstart)\r\n                        LEFT JOIN serie AS s ON (ss.xSerie = s.xSerie)\r\n                    WHERE   \r\n                    {$roundSQL}\r\n                    AND r.Leistung <= 0\r\n                    ORDER BY\r\n                        ss.xSerienstart\r\n                        ,r.Leistung DESC";
                        $result = mysql_query($sql);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            while ($row = mysql_fetch_row($result)) {
                                mysql_query("\r\n                            UPDATE serienstart SET\r\n                                Rang = 0\r\n                            WHERE xSerienstart = {$row['2']}\r\n                        ");
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                        }
                        $result = mysql_query("\r\n                    SELECT\r\n                        r.Leistung\r\n                        , r.Info\r\n                        , ss.xSerienstart\r\n                        , ss.xSerie\r\n                    FROM\r\n                       resultat as r\r\n                        LEFT JOIN serienstart as ss ON (r.xSerienstart = ss.xSerienstart)\r\n                        LEFT JOIN serie AS s ON (ss.xSerie = s.xSerie)\r\n                    WHERE \r\n                    {$roundSQL}\r\n                    AND r.Leistung >= 0\r\n                    ORDER BY\r\n                        ss.xSerienstart\r\n                        ,r.Leistung DESC\r\n                ");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $ss = 0;
                            $i = 0;
                            // process every result
                            while ($row = mysql_fetch_row($result)) {
                                if ($ss != $row[2]) {
                                    // add one row per athlete to temp table
                                    if ($ss != 0) {
                                        for (; $i < $r; $i++) {
                                            // fill remaining result cols.
                                            $qry = $qry . ",0,''";
                                        }
                                        mysql_query($qry . ")");
                                        if (mysql_errno() > 0) {
                                            // DB error
                                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                        }
                                    }
                                    // (re)set SQL statement
                                    $qry = "INSERT INTO tempresult VALUES({$row['2']},{$row['3']}";
                                    $i = 0;
                                }
                                $qry = $qry . ",{$row['0']},'{$row['1']}'";
                                // add current result to query
                                $ss = $row[2];
                                // keep athlete's ID
                                $i++;
                                // count nbr of results
                            }
                            mysql_free_result($result);
                            // insert last pending data in temp table
                            if ($ss != 0) {
                                for (; $i < $r; $i++) {
                                    // fill remaining result cols.
                                    $qry = $qry . ",0,''";
                                }
                                mysql_query($qry . ")");
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                        }
                        if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                            // eval per heat
                            $qry = "\r\n                        SELECT\r\n                            *\r\n                        FROM\r\n                            tempresult\r\n                        ORDER BY\r\n                            xSerie";
                            for ($i = 1; $i <= $r; $i++) {
                                $qry = $qry . ", Res" . $i . " DESC";
                            }
                        } else {
                            // default: rank results from all heats together
                            $qry = "\r\n                        SELECT\r\n                            *\r\n                        FROM\r\n                            tempresult\r\n                        ORDER BY ";
                            $comma = "";
                            // order by available result columns
                            for ($i = 1; $i <= $r; $i++) {
                                $qry = $qry . $comma . "Res" . $i . " DESC";
                                $comma = ", ";
                            }
                        }
                        $result = mysql_query($qry);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $heat = 0;
                            $perf_old[] = '';
                            $j = 0;
                            $rank = 0;
                            // set rank for every athlete
                            while ($row = mysql_fetch_row($result)) {
                                for ($i = 0; $i <= $r; $i++) {
                                    $perf[$i] = $row[2 * $i + 2];
                                    $wind[$i] = $row[2 * $i + 3];
                                }
                                if ($eval == $cfgEvalType[$strEvalTypeHeat] && $heat != $row[1]) {
                                    $j = 0;
                                    // restart ranking
                                    $perf_old[] = '';
                                }
                                $j++;
                                // increment ranking
                                if ($perf_old != $perf) {
                                    // compare performances
                                    $rank = $j;
                                    // next rank (only if not same performance)
                                }
                                mysql_query("\r\n                            UPDATE serienstart SET\r\n                                Rang = {$rank}\r\n                            WHERE xSerienstart = {$row['0']}\r\n                        ");
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                                $heat = $row[1];
                                // keep current heat ID
                                $perf_old = $perf;
                            }
                            mysql_free_result($result);
                        }
                        mysql_query("DROP TABLE IF EXISTS tempresult");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                    }
                    // ET DB error (create temp table)
                    mysql_query("UNLOCK TABLES");
                }
                // ET DB error (drop temp table)
            }
            // ET any results found
            AA_results_setNotStarted($round);
            // update athletes with no result
            if ($_GET['arg'] == 'results_done') {
                AA_utils_changeRoundStatus($round, $cfgRoundStatus['results_done']);
            }
            if (!empty($GLOBALS['AA_ERROR'])) {
                AA_printErrorMsg($GLOBALS['AA_ERROR']);
            }
            AA_results_resetQualification($round);
        }
        //
        // calculate ranking points if needed
        //
        if ($_GET['arg'] == 'results_done' || $_POST['arg'] == 'save_rank' || $prog_mode == 2 && $_GET['arg'] != 'change_results' && $_GET['arg'] != 'del_results') {
            AA_utils_calcRankingPoints($round);
        }
        //
        // Qualify athletes after ranks are set
        //
        if ($_GET['arg'] == 'results_done' || $_POST['arg'] == 'save_rank' || $_POST['arg'] == 'set_qual' || $prog_mode == 2 && $_GET['arg'] != 'change_results' && $_GET['arg'] != 'del_results') {
            // read qualification criteria
            $qual_top = 0;
            $qual_perf = 0;
            $result = mysql_query("SELECT QualifikationSieger" . ", QualifikationLeistung" . " FROM runde" . " WHERE xRunde = " . $round);
            if (mysql_errno() > 0) {
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                if (($row = mysql_fetch_row($result)) == TRUE) {
                }
                $qual_top = $row[0];
                $qual_perf = $row[1];
                mysql_free_result($result);
            }
            // ET DB error
            // qualify top athletes for next round
            if ($qual_top > 0) {
                mysql_query("LOCK TABLES serie READ, serienstart WRITE");
                // get athletes by qualifying rank (random order if same rank)
                $result = mysql_query("SELECT serienstart.xSerienstart" . ", serienstart.xSerie" . ", serienstart.Rang" . " FROM serienstart" . ", serie" . " WHERE serienstart.Rang > 0" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round . " AND serienstart.Qualifikation = 0" . " ORDER BY serienstart.xSerie" . ", serienstart.Rang ASC" . ", RAND()");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    $h = 0;
                    unset($heats);
                    // clear array containing heats
                    while ($row = mysql_fetch_row($result)) {
                        if ($h != $row[1]) {
                            // new heat
                            if (count($starts) > 0) {
                                // count athletes
                                $heats[] = $starts;
                                // keep athletes per heat
                            }
                            unset($starts);
                            $c = 0;
                        }
                        $starts[$row[0]] = $row[2];
                        // keep athlete's rank
                        $h = $row[1];
                        // keep heat
                    }
                    $heats[] = $starts;
                    // keep remaining athletes
                    mysql_free_result($result);
                    foreach ($heats as $starts) {
                        $rankcount = array_count_values($starts);
                        // count athletes/rank
                        $q = 0;
                        foreach ($starts as $id => $rank) {
                            // check if more athletes per rank than qualifying spots
                            if ($rankcount[$rank] > $qual_top - $rank + 1) {
                                $qual = $cfgQualificationType['top_rand']['code'];
                            } else {
                                $qual = $cfgQualificationType['top']['code'];
                            }
                            if ($q < $qual_top) {
                                mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $qual . " WHERE xSerienstart = " . $id);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                                $q++;
                                // count nbr of qualified athletes
                            }
                        }
                    }
                    // END loop every heat
                }
                // ET DB error
                mysql_query("UNLOCK TABLES");
            }
            // ET top athletes
            // qualify top performing athletes for next round
            if ($qual_perf > 0) {
                mysql_query("LOCK TABLES resultat READ, serie READ, serienstart WRITE");
                // get remaining athletes by performance (random order if equal performance)
                /* other possible criteria to order equal performances:
                 * - ranking within heat (not implemented)
                 * - wind (not implemented)
                 */
                $result = mysql_query("SELECT serienstart.xSerienstart" . ", resultat.Leistung" . ", serienstart.Qualifikation" . " FROM resultat" . ", serienstart" . ", serie" . " WHERE resultat.xSerienstart = serienstart.xSerienstart" . " AND resultat.Leistung > 0" . " AND (serienstart.Qualifikation = 0 " . " OR serienstart.Qualifikation = " . $cfgQualificationType['waived']['code'] . ")" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round . " ORDER BY resultat.Leistung DESC" . ", RAND()");
                if (mysql_errno() > 0) {
                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                } else {
                    $i = 1;
                    $perf = 0;
                    $cWaived = 0;
                    while ($row = mysql_fetch_row($result)) {
                        // count waived qualifyings
                        if ($row[2] == $cfgQualificationType['waived']['code']) {
                            $cWaived++;
                            continue;
                        }
                        if ($i > $qual_perf) {
                            // terminate if enough top performers found
                            if ($perf != $row[1]) {
                                // last perf. worse than last qualified
                                $perf = 0;
                            }
                            break;
                        }
                        // if athletes waived on qualifying, set random code for next best athletes
                        $code = $cfgQualificationType['perf']['code'];
                        if ($i + $cWaived > $qual_perf) {
                            $code = $cfgQualificationType['perf_rand']['code'];
                        }
                        mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $code . " WHERE xSerienstart = " . $row[0]);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        $i++;
                        $perf = $row[1];
                        // keep performance
                    }
                    // reset performance if enough qualifing spots
                    if (mysql_num_rows($result) <= $qual_perf) {
                        $perf = 0;
                    }
                    mysql_free_result($result);
                    // Change qualification type to "perf_rand" for athletes with same
                    // performance as the 1st unqualified athlete
                    if ($perf != 0) {
                        $result = mysql_query("SELECT serienstart.xSerienstart" . " FROM resultat" . ", serienstart" . ", serie" . " WHERE resultat.xSerienstart = serienstart.xSerienstart" . " AND resultat.Leistung = " . $perf . " AND serienstart.Qualifikation > 0" . " AND serienstart.xSerie = serie.xSerie" . " AND serie.xRunde = " . $round);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            while ($row = mysql_fetch_row($result)) {
                                mysql_query("UPDATE serienstart SET" . " Qualifikation = " . $cfgQualificationType['perf_rand']['code'] . " WHERE xSerienstart = " . $row[0]);
                                if (mysql_errno() > 0) {
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                }
                            }
                            mysql_free_result($result);
                        }
                    }
                    // ET unqualified athlete
                }
                // ET DB error qualified by performance
                mysql_query("UNLOCK TABLES");
            }
            // ET top performances
        }
        //
        // print HTML page header
        //
        AA_results_printHeader($presets['category'], $presets['event'], $round);
        $mergedMain = AA_checkMainRound($round);
        if ($mergedMain != 1) {
            // read round data
            if ($round > 0) {
                $status = AA_getRoundStatus($round);
                // No action yet
                if ($status == $cfgRoundStatus['open'] || $status == $cfgRoundStatus['enrolement_done'] || $status == $cfgRoundStatus['heats_in_progress']) {
                    AA_printWarningMsg($strHeatsNotDone);
                } else {
                    if ($status == $cfgRoundStatus['enrolement_pending']) {
                        AA_printWarningMsg($strEnrolementNotDone);
                    } else {
                        if ($status >= $cfgRoundStatus['heats_done']) {
                            // get program mode
                            $prog_mode = AA_results_getProgramMode();
                            AA_heats_printNewStart($presets['event'], $round, "event_results.php");
                            if ($pass == 2) {
                                $fieldPos = "ss.Position2";
                                $order = "posOrder";
                            } elseif ($pass == 3) {
                                $fieldPos = "ss.Position3";
                                $order = "ss.Rang DESC";
                            } else {
                                $fieldPos = "ss.Position";
                                $order = "posOrder";
                            }
                            // display all athletes
                            $sql = "SELECT rt.Name" . ", rt.Typ" . ", s.xSerie" . ", s.Bezeichnung" . ", s.Wind" . ", an.Bezeichnung" . ", ss.xSerienstart" . ", ss.Position" . ", ss.Rang" . ", a.Startnummer" . ", at.Name" . ", at.Vorname" . ", at.Jahrgang" . ", if('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo))" . ", LPAD(s.Bezeichnung,5,'0') as heatid" . ", r.Versuche" . ", ss.Qualifikation" . ", at.Land" . ", r.nurBestesResultat" . ", ss.Bemerkung" . ", at.xAthlet" . ",  if (ss.Position2 > 0, if (ss.Position3 > 0, ss.Position3, ss.Position2) , ss.Position ) as posOrder  " . " FROM runde AS r" . ", serie AS s" . ", serienstart AS ss" . ", start AS st" . ", anmeldung AS a" . ", athlet AS at" . ", verein AS v" . " LEFT JOIN team AS t ON(a.xTeam = t.xTeam)" . " LEFT JOIN rundentyp AS rt" . " ON rt.xRundentyp = r.xRundentyp" . " LEFT JOIN anlage AS an" . " ON an.xAnlage = s.xAnlage" . " WHERE r.xRunde = " . $round . " AND s.xRunde = r.xRunde" . " AND ss.xSerie = s.xSerie" . " AND st.xStart = ss.xStart" . " AND a.xAnmeldung = st.xAnmeldung" . " AND at.xAthlet = a.xAthlet" . " AND v.xVerein = at.xVerein" . " ORDER BY heatid, posOrder";
                            $result = mysql_query($sql);
                            if (mysql_errno() > 0) {
                                // DB error
                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                            } else {
                                $sum_athlet = mysql_num_rows($result);
                                AA_results_printMenu($round, $status, $prog_mode, 'tech');
                                // initialize variables
                                $h = 0;
                                $i = 0;
                                $r = 0;
                                $rowclass = 'odd';
                                $r_rem = 0;
                                $nextRound = AA_getNextRound($presets['event'], $round);
                                // show qualification form if another round follows
                                if ($nextRound > 0) {
                                    // next round
                                    $sql = "SELECT QualifikationSieger, \r\n                               QualifikationLeistung \r\n                          FROM runde \r\n                         WHERE xRunde = " . $round . ";";
                                    $result2 = mysql_query($sql);
                                    if (mysql_errno() > 0) {
                                        // DB error
                                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                    } else {
                                        $row2 = mysql_fetch_row($result2);
                                        if ($row2 == true) {
                                            // round found
                                            ?>
                        <p/>
                            <form name="qualification" action="event_results.php" method="post">
                                <input type="hidden" name="arg" value="set_qual"/>
                                <input type="hidden" name="round" value="<?php 
                                            echo $round;
                                            ?>
"/>
                                <table class="dialog">
                                    <tr>
                                        <td class="dialog"><?php 
                                            echo $strQualification;
                                            ?>
 <?php 
                                            echo $strQualifyTop;
                                            ?>
</td>
                                        <td class="dialog"><input type="text" name="qual_top" class="nbr" maxlength="4" value="<?php 
                                            echo $row2[0];
                                            ?>
"/></td>
                                        <td class='dialog'><?php 
                                            echo $strQualification;
                                            ?>
 <?php 
                                            echo $strQualifyPerformance;
                                            ?>
</td>
                                        <td class='dialog'><input type="text" name="qual_perf" class="nbr" maxlength="4" value="<?php 
                                            echo $row2[1];
                                            ?>
"/></td>
                                        <td><button type="submit"><?php 
                                            echo $strChange;
                                            ?>
</button></td>
                                    </tr>
                                </table>
                            </form>
                            
                            <form name="frmQual" action="event_results.php" method="post">
                                <input type="hidden" name="arg" value="change_qual"/>
                                <input type="hidden" name="round" value="<?php 
                                            echo $round;
                                            ?>
"/>
                                <input type="hidden" name="focus" value="qual_0"/>
                                <input type="hidden" name="item" value="0"/>
                                <input type="hidden" name="oldqual" value="0"/>
                                <input type="hidden" name="heat" value="0"/>
                                <input type="hidden" name="qual" value="0"/>
                            </form>
                            <script type="text/javascript">
                                function changequal(valFocus, valItem, valOldQual, valHeat, valQual){
                                    var obj = document.frmQual;
                                    
                                    obj.focus.value = valFocus;
                                    obj.item.value = valItem;
                                    obj.oldqual.value = valOldQual;
                                    obj.heat.value = valHeat;
                                    obj.qual.value = valQual;
                                    obj.submit();
                                }
                            </script>
                        <p/>
                        <?php 
                                        }
                                        // ET round found
                                    }
                                    // ET DB error
                                }
                                // ET next round
                                ?>
<p/>
<table class='dialog'>
<?php 
                                $btn = new GUI_Button('', '');
                                // create button object
                                while ($row = mysql_fetch_row($result)) {
                                    //
                                    // get entered number of attempts
                                    //
                                    $maxatt = $row[15];
                                    if ($maxatt != 0) {
                                        $cfgProgramMode[$prog_mode]['tech_res'] = $maxatt;
                                    }
                                    /*
                                     *  Heat headerline
                                     */
                                    if ($h != $row[2]) {
                                        $h = $row[2];
                                        // keep heat ID
                                        if (is_null($row[0])) {
                                            // only one round
                                            $title = "{$strFinalround}";
                                        } else {
                                            // more than one round
                                            $title = "{$row['0']}";
                                        }
                                        $c = 0;
                                        if ($status == $cfgRoundStatus['results_done'] || $prog_mode == 2) {
                                            $c++;
                                            // increment colspan to include ranking
                                        }
                                        ?>
    <tr>
        <form action='event_results.php#heat_<?php 
                                        echo $row[3];
                                        ?>
' method='post'
            name='heat_id_<?php 
                                        echo $h;
                                        ?>
'>

        <th class='dialog' colspan='
<?php 
                                        echo 5 + $cfgProgramMode[$prog_mode]['tech_res'] + $c;
                                        ?>
'>
            <?php 
                                        echo $title;
                                        ?>
            <input type='hidden' name='arg' value='change_heat_name' />
            <input type='hidden' name='round' value='<?php 
                                        echo $round;
                                        ?>
' />
            <input type='hidden' name='item' value='<?php 
                                        echo $row[2];
                                        ?>
' />
            <input class='nbr' type='text' name='id' maxlength='2'
                value='<?php 
                                        echo $row[3];
                                        ?>
'
                onChange='document.heat_id_<?php 
                                        echo $h;
                                        ?>
.submit()' />
                <a name='heat_<?php 
                                        echo $row[3];
                                        ?>
' />
        </th>
        </form>
    </tr>

    <tr>
        <th class='dialog'><?php 
                                        echo $strPositionShort;
                                        ?>
</th>
        <th class='dialog' colspan='2'><?php 
                                        echo $strAthlete;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        echo $strYearShort;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        echo $strCountry;
                                        ?>
</th>
        <th class='dialog'><?php 
                                        if ($svm) {
                                            echo $strTeam;
                                        } else {
                                            echo $strClub;
                                        }
                                        ?>
</th>
<?php 
                                        if ($status == $cfgRoundStatus['results_done'] || $prog_mode == 2) {
                                            ?>
        <th class='dialog'><?php 
                                            echo $strRank;
                                            ?>
</th>
<?php 
                                            if ($nextRound > 0) {
                                                ?>
        <th class='dialog'><?php 
                                                echo $strQualification;
                                                ?>
</th>
<?php 
                                            }
                                        }
                                        if ($cfgProgramMode[$prog_mode]['tech_res'] <= 1) {
                                            ?>
        <th class='dialog'><?php 
                                            echo $strPerformance;
                                            ?>
</th>
<?php 
                                        } else {
                                            for ($c = 1; $c <= $cfgProgramMode[$prog_mode]['tech_res']; $c++) {
                                                ?>
        <th class='dialog'><?php 
                                                echo $c . ".";
                                                ?>
</th>
<?php 
                                            }
                                            ?>
 
                    <th class='dialog'><?php 
                                            echo $strResultRemark;
                                            ?>
</th> 
<?php 
                                        }
                                        ?>
    </tr>
<?php 
                                    }
                                    // ET new heat
                                    /*
                                     * Athlete data lines
                                     */
                                    $i++;
                                    if ($row[7] % 2 == 0) {
                                        // even row numer
                                        $rowclass = 'odd';
                                    } else {
                                        // odd row number
                                        $rowclass = 'even';
                                    }
                                    ?>
    <tr class='<?php 
                                    echo $rowclass;
                                    ?>
'>
        <td class='forms_right'><?php 
                                    echo $row[7];
                                    /* position */
                                    ?>
</td>
        <td class='forms_right'><?php 
                                    echo $row[9];
                                    /* start nbr */
                                    ?>
</td>
        <td nowrap><?php 
                                    echo $row[10] . " " . $row[11];
                                    /* name */
                                    ?>
</td>
        <td class='forms_ctr'><?php 
                                    echo AA_formatYearOfBirth($row[12]);
                                    ?>
</td>
        <td><?php 
                                    echo $row[17] != '' && $row[17] != '-' ? $row[17] : '&nbsp;';
                                    ?>
</td>
        <td nowrap><?php 
                                    echo $row[13];
                                    /* club */
                                    ?>
</td>
<?php 
                                    $res = mysql_query("SELECT rs.xResultat" . ", rs.Leistung" . ", rs.Info" . " FROM resultat AS rs" . " WHERE rs.xSerienstart = " . $row[6] . "\r\n                    ORDER BY rs.xResultat");
                                    if (mysql_errno() > 0) {
                                        // DB error
                                        AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                    } else {
                                        // Show rank
                                        if ($status == $cfgRoundStatus['results_done'] || $prog_mode == 2) {
                                            $disField = ($maxatt + 1) * $maxAthlete;
                                            // attempts * 8 (first 8 athletes)
                                            if ($pass >= 2 && $r + 1 > $disField) {
                                                $dis = 'disabled=" disabled"';
                                            } else {
                                                $dis = '';
                                            }
                                            ?>
        <form action='event_results.php' method='post'
            name='rank_<?php 
                                            echo $r;
                                            ?>
'>
        <td>
            <input type='hidden' name='arg' value='save_rank' />
            <input type='hidden' name='round' value='<?php 
                                            echo $round;
                                            ?>
' />
            <input type='hidden' name='item' value='<?php 
                                            echo $row[6];
                                            ?>
' />
            <input type='hidden' name='focus' value='rank_<?php 
                                            echo $r;
                                            ?>
' />
            <input class='nbr' type='text' name='rank' maxlength='3'   <?php 
                                            echo $dis;
                                            ?>
   
                value='<?php 
                                            echo $row[8];
                                            ?>
' onChange='document.rank_<?php 
                                            echo $r;
                                            ?>
.submit()' />
        </td>
        <?php 
                                            if ($status == $cfgRoundStatus['results_done'] || $prog_mode == 2) {
                                                if ($nextRound > 0) {
                                                    ?>
                            <form name="qual_<?php 
                                                    echo $i;
                                                    ?>
" action="event_results.php" method="post">
                                <td>
                                    <input type="hidden" name="arg" value="change_qual"/>
                                    <input type="hidden" name="round" value="<?php 
                                                    echo $round;
                                                    ?>
"/>
                                    <input type="hidden" name="focus" value="qual_<?php 
                                                    echo $i;
                                                    ?>
"/>
                                    <input type="hidden" name="item" value="<?php 
                                                    echo $row[6];
                                                    ?>
"/>
                                    <input type="hidden" name="oldqual" value="<?php 
                                                    echo $row[16];
                                                    ?>
"/>
                                    <input type="hidden" name="heat" value="<?php 
                                                    echo $row[2];
                                                    ?>
"/>
                                    <?php 
                                                    $dropdown = new GUI_Select('qual', 1, 'changequal("qual_' . $i . '", ' . $row[6] . ', ' . $row[16] . ', ' . $row[2] . ', this.value)');
                                                    $dropdown->addOptionNone();
                                                    foreach ($cfgQualificationType as $type) {
                                                        $dropdown->addOption($type['text'], $type['code']);
                                                        if ($type['code'] == $row[16]) {
                                                            $dropdown->selectOption($type['code']);
                                                        }
                                                    }
                                                    $dropdown->printList();
                                                    ?>
                                </td>
                            </form>
                            <?php 
                                                    $i++;
                                                    // next element
                                                }
                                                // qualification info
                                            } else {
                                                // no rank
                                                ?>
        <td />
<?php 
                                                if ($nextRound > 0) {
                                                    ?>
        <td />
<?php 
                                                }
                                            }
                                            // ET valid rank
                                            ?>
        </form>
<?php 
                                        }
                                        $disField = ($maxatt + 1) * $maxAthlete;
                                        // attempts * 8 (first 8 athletes)
                                        for ($c = 1; $c <= $cfgProgramMode[$prog_mode]['tech_res']; $c++) {
                                            // Result focus:
                                            // - Backoffice mode: same athlete, next result
                                            // - Field mode: next athlete, same result
                                            $r++;
                                            // increment result form counter
                                            if ($cfgProgramMode[$prog_mode]['name'] == $strProgramModeBackoffice) {
                                                if ($row[18] == 'y') {
                                                    // only best result --> focus next line
                                                    $focus = "perf_" . ($r + $cfgProgramMode[$prog_mode]['tech_res'] + 1);
                                                    if (mysql_num_rows($result) == $i) {
                                                        // no more athletes
                                                        if ($c == $cfgProgramMode[$prog_mode]['tech_res']) {
                                                            // last result
                                                            $focus = "perf_" . ($r + 1);
                                                            // keep focus on this athlete
                                                        } else {
                                                            $focus = "perf_" . ($c + 1);
                                                            // focus to next result of first athlete
                                                        }
                                                    }
                                                } else {
                                                    if ($c == $cfgProgramMode[$prog_mode]['tech_res']) {
                                                        // last result of this line
                                                        if (mysql_num_rows($result) == $i) {
                                                            // no more athletes
                                                            $focus = "perf_" . $r;
                                                            // keep focus on last athlete
                                                        } else {
                                                            $focus = "perf_" . ($r + 2);
                                                            // focus to next line result
                                                        }
                                                    } else {
                                                        $focus = "perf_" . ($r + 1);
                                                        // focus to next result
                                                    }
                                                }
                                            } else {
                                                // field mode
                                                $focus = "perf_" . ($r + $cfgProgramMode[$prog_mode]['tech_res'] + 1);
                                                if (mysql_num_rows($result) == $i) {
                                                    // no more athletes
                                                    if ($c == $cfgProgramMode[$prog_mode]['tech_res']) {
                                                        // last result
                                                        $focus = "perf_" . $r;
                                                        // keep focus on this athlete
                                                    } else {
                                                        $focus = "perf_" . ($c + 1);
                                                        // focus to next result of first athlete
                                                    }
                                                }
                                            }
                                            // ET program mode
                                            $item = '';
                                            $perf = '';
                                            $info = '';
                                            if ($resrow = mysql_fetch_row($res)) {
                                                $item = $resrow[0];
                                                $perf = AA_formatResultMeter($resrow[1]);
                                                $info = $resrow[2];
                                            }
                                            if ($status != $cfgRoundStatus['results_done'] || $prog_mode == 2) {
                                                ?>
        <form action='controller.php' method='post'
            name='perf_<?php 
                                                echo $r;
                                                ?>
' target='controller'>
        <td nowrap>
            <input type='hidden' name='act' value='saveResult' />
            <input type='hidden' name='obj' value='perf_<?php 
                                                echo $r;
                                                ?>
' />
            <input type='hidden' name='type' value='<?php 
                                                echo $layout;
                                                ?>
' />
            <input type='hidden' name='round' value='<?php 
                                                echo $round;
                                                ?>
' />
            <input type='hidden' name='start' value='<?php 
                                                echo $row[6];
                                                ?>
' />
            <input type='hidden' name='item' value='<?php 
                                                echo $item;
                                                ?>
' />  
            <input type='hidden' name='row_col' value='<?php 
                                                echo $r . "_" . $c;
                                                ?>
' />  
            <input type='hidden' name='maxatt' value='<?php 
                                                echo $maxatt;
                                                ?>
' />   
             <input type='hidden' name='heat' value='<?php 
                                                echo $row[2];
                                                ?>
' />         
            
<?php 
                                                // technical disciplines with wind
                                                if ($layout == $cfgDisciplineType[$strDiscTypeJump]) {
                                                    ?>
            <input class='perfmeter' type='text' id='perf_<?php 
                                                    echo $r;
                                                    ?>
' name='perf' maxlength='6'  <?php 
                                                    echo $dis;
                                                    ?>
 
                value='<?php 
                                                    echo $perf;
                                                    ?>
'
                onChange='checkSubmit(document.perf_<?php 
                                                    echo $r;
                                                    ?>
, <?php 
                                                    echo $focus;
                                                    ?>
)' />
            <input class='nbr' type='text' name='wind' maxlength='5'
                value='<?php 
                                                    echo $info;
                                                    ?>
'
                onChange='submitResult(document.perf_<?php 
                                                    echo $r;
                                                    ?>
, <?php 
                                                    echo $focus;
                                                    ?>
)' />
<?php 
                                                } else {
                                                    ?>
            <input class='perfmeter' type='text' id='perf_<?php 
                                                    echo $r;
                                                    ?>
'  name='perf' maxlength='6'  <?php 
                                                    echo $dis;
                                                    ?>
                value='<?php 
                                                    echo $perf;
                                                    ?>
'
                onChange='submitResult(document.perf_<?php 
                                                    echo $r;
                                                    ?>
, <?php 
                                                    echo $focus;
                                                    ?>
)' />
            
<?php 
                                                }
                                                ?>
        </td>
        </form>    
<?php 
                                                if ($c == $cfgProgramMode[$prog_mode]['tech_res']) {
                                                    $r++;
                                                    if (mysql_num_rows($result) != $i) {
                                                        //  more athletes
                                                        $focus = "perf_" . ($c + $r + 1);
                                                    } else {
                                                        $focus = "perf_" . $r;
                                                    }
                                                    ?>
                            
       <form action='controller.php' method='post'  
            name='perf_<?php 
                                                    echo $r;
                                                    ?>
' target='controller'>   
        <td>
        <input type='hidden' name='act' value='saveResult' />
            <input type='hidden' name='obj' value='perf_<?php 
                                                    echo $r;
                                                    ?>
' />
            <input type='hidden' name='type' value='<?php 
                                                    echo $layout;
                                                    ?>
' />
            <input type='hidden' name='round' value='<?php 
                                                    echo $round;
                                                    ?>
' />
            <input type='hidden' name='start' value='<?php 
                                                    echo $row[6];
                                                    ?>
' />
            <input type='hidden' name='item' value='<?php 
                                                    echo $item;
                                                    ?>
' />
            <input type='hidden' name='xAthlete' value='<?php 
                                                    echo $row[20];
                                                    ?>
' /> 
             
        <input class='textshort' type='text' name='remark' maxlength='5'   <?php 
                                                    echo $dis;
                                                    ?>
   
                value='<?php 
                                                    echo $row[19];
                                                    ?>
'
                onChange='submitResult(document.perf_<?php 
                                                    echo $r;
                                                    ?>
, <?php 
                                                    echo $focus;
                                                    ?>
)' />
                </td>
        </form>    
<?php 
                                                }
                                                ?>
        
        
<?php 
                                            } else {
                                                // results done
                                                ?>
        <td nowrap>
<?php 
                                                // technical disciplines with wind
                                                if ($layout == $cfgDisciplineType[$strDiscTypeJump]) {
                                                    echo "{$perf} ( {$info} )";
                                                } else {
                                                    echo "{$perf}";
                                                }
                                                ?>
        </td>
<?php 
                                                if ($c == $cfgProgramMode[$prog_mode]['tech_res']) {
                                                    ?>
  
                                <td nowrap><?php 
                                                    echo $row[19];
                                                    ?>
</td>
<?php 
                                                }
                                            }
                                            // ET results done
                                        }
                                        // end loop every tech result acc. programm mode
                                        ?>
  
          
        <td>
<?php 
                                        $btn->set("event_results.php?arg=del_start&item={$row['6']}&round={$round}", $strDelete);
                                        $btn->printButton();
                                        ?>
        </td>
<?php 
                                    }
                                    // ET DB error
                                }
                                ?>
</table>
<?php 
                                mysql_free_result($result);
                            }
                            // ET DB error
                        }
                    }
                }
            }
            // ET round selected
            if (!empty($presets['focus'])) {
                ?>
<script type="text/javascript">
<!--
    if(document.<?php 
                echo $presets['focus'];
                ?>
) {
        document.<?php 
                echo $presets['focus'];
                ?>
.rank.focus();
        document.<?php 
                echo $presets['focus'];
                ?>
.rank.select();
        window.scrollBy(0,200);
    }
//-->
</script>
<?php 
            } else {
                ?>
    <script type="text/javascript">
<!--
      
      document.perf_<?php 
                echo $fieldFocus;
                ?>
.elements['perf_<?php 
                echo $fieldFocus;
                ?>
'].focus();
//-->
</script>
<?php 
            }
            ?>

</body>
</html>

<?php 
        } else {
            AA_printErrorMsg($strErrMergedRound);
        }
    }