function AA_regie_High($event, $round, $layout, $cat, $disc)
 {
     require './lib/cl_gui_resulttable.lib.php';
     require './config.inc.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     $status = AA_getRoundStatus($round);
     mysql_query("\r\n                LOCK TABLES\r\n                    resultat READ\r\n                    , serie READ\r\n                    , start READ                    \r\n                    , serienstart READ\r\n                    , serienstart READ                   \r\n                    , serie AS S READ\r\n                    , start AS ST READ                      \r\n                    , serienstart AS SS READ\r\n                    , anmeldung AS A READ \r\n                    , athlet as at READ \r\n                    , verein as vREAD \r\n                    , rundentyp as rt READ   \r\n                    , tempHigh WRITE\r\n            ");
     mysql_query("TRUNCATE TABLE tempHigh");
     // 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 High table
                     mysql_query("\r\n                                    INSERT INTO tempHigh\r\n                                    VALUES(\r\n                                        {$serienstart}\r\n                                        , {$serie}\r\n                                        , {$leistung}\r\n                                        , {$topX}\r\n                                        , {$totX}\r\n                                        , 0)\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 tempHigh table
         if ($ss != 0 && $leistung != 0) {
             mysql_query("\r\n                            INSERT INTO tempHigh\r\n                            VALUES(\r\n                                {$serienstart}\r\n                                , {$serie}\r\n                                , {$leistung}\r\n                                , {$topX}\r\n                                , {$totX}\r\n                                , 0)\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                        tempHigh\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 tempHigh 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);
     }
     $arg = isset($_GET['arg1']) ? $_GET['arg1'] : (isset($_COOKIE['sort_speakres']) ? $_COOKIE['sort_speakres'] : 'pos');
     setcookie('sort_speakres', $arg1, time() + 2419200);
     // display all athletes
     if ($arg == "pos") {
         $argument = "ss.Position";
         $img_pos = "img/sort_act.gif";
     } else {
         if ($arg == "rang") {
             $argument = "orderRang, ss.Position";
             $img_rang = "img/sort_act.gif";
         } else {
             if ($relay == FALSE) {
                 // single event
                 $argument = "ss.Position";
                 $img_pos = "img/sort_act.gif";
             }
         }
     }
     $result = mysql_query("\r\n\t\t\tSELECT\r\n\t\t\t\trt.Name\r\n\t\t\t\t, rt.Typ\r\n\t\t\t\t, s.xSerie\r\n\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t, s.Status\r\n\t\t\t\t, ss.xSerienstart\r\n\t\t\t\t, ss.Position\r\n\t\t\t\t, ss.Rang\r\n\t\t\t\t, a.Startnummer\r\n\t\t\t\t, at.Name\r\n\t\t\t\t, at.Vorname\r\n\t\t\t\t, at.Jahrgang\r\n\t\t\t\t, v.Name\r\n\t\t\t\t, LPAD(s.Bezeichnung,5,'0') as heatid\r\n\t\t\t\t, st.Bestleistung\r\n\t\t\t\t, at.xAthlet\r\n\t\t\t\t, at.Land                  \r\n                , if (t.rang > 0,  t.rang, 999999) as orderRang \r\n\t\t\tFROM\r\n\t\t\t\trunde AS r\r\n\t\t\t\tLEFT JOIN serie AS s ON (s.xRunde = r.xRunde )\r\n\t\t\t\tLEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n\t\t\t\tLEFT JOIN start AS st ON (st.xStart = ss.xStart)\r\n\t\t\t\tLEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n\t\t\t\tLEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n\t\t\t\tLEFT JOIN verein AS v ON (v.xVerein = at.xVerein)\r\n                LEFT JOIN tempHigh AS t ON (t.xSerienstart = ss.xSerienstart)    \r\n\t\t\t    LEFT JOIN rundentyp AS rt ON (rt.xRundentyp = r.xRundentyp)\r\n\t\t\tWHERE r.xRunde = {$round}   \t\t\t\r\n\t\t\tORDER BY                     \r\n\t\t\t\theatid ,\r\n\t\t\t\t" . $argument);
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         // initialize variables
         $h = 0;
         $i = 0;
         $current_athlete = false;
         $curr_class = '';
         $resTable = new GUI_HighResultTable($round, $layout, $status);
         $resTable->printHeatTitleRegie($cat, $disc);
         while ($row = mysql_fetch_row($result)) {
             /*
              *  Heat headerline
              */
             if ($h != $row[2]) {
                 $h = $row[2];
                 // keep heat ID
                 if (is_null($row[0])) {
                     // only one round
                     $title = "{$strFinalround}  {$row['3']}";
                 } else {
                     // more than one round
                     $title = "{$row['0']}: {$row['1']}{$row['3']}";
                 }
                 $c = 0;
                 if ($status == $cfgRoundStatus['results_done']) {
                     $c = 1;
                     // increment colspan to include ranking
                 }
                 $resTable->printHeatTitle($row[2], $row[3], $title, $row[4], 'regie');
                 $resTable->printAthleteHeader('regie');
             }
             // ET new heat
             /*
              * Athlete data lines
              */
             $rank = '';
             $perfs = array();
             $res = mysql_query("\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\tr.Leistung\r\n\t\t\t\t\t\t, r.Info\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tresultat as r\r\n\t\t\t\t\tWHERE r.xSerienstart = {$row['5']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\tr.xResultat DESC\r\n\t\t\t\t");
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 if ($status == $cfgRoundStatus['results_done']) {
                     $rank = $row[7];
                 } else {
                     $rank = $row[17];
                 }
                 while ($resrow = mysql_fetch_row($res)) {
                     $perf = AA_formatResultMeter($resrow[0]);
                     $info = $resrow[1];
                     $perfs[] = "{$perf} ( {$info} )";
                 }
                 // end loop every tech result acc. programm mode
                 mysql_free_result($res);
             }
             $heatStart = AA_getCurrAthlete($row[2]);
             if ($heatStart > 0) {
                 if ($row[5] == $heatStart) {
                     $curr_class = "active";
                 }
             } else {
                 if (empty($perfs) && !$current_athlete) {
                     $current_athlete = true;
                     $curr_class = "active";
                 }
             }
             if ($rank == 999999) {
                 $rank = '';
             }
             $resTable->printAthleteLine($row[6], $row[8], "{$row['9']} {$row['10']}", '', '', AA_formatResultMeter($row[14]), $perfs, $fett, $rank, '', $row[15], $curr_class, 'regie');
             $curr_class = "";
         }
         $resTable->endTable();
         mysql_free_result($result);
     }
     // ET DB error
     mysql_query("UNLOCK TABLES");
 }
    function AA_speaker_High($event, $round, $layout)
    {
        require './lib/cl_gui_resulttable.lib.php';
        require './config.inc.php';
        require './lib/common.lib.php';
        require './lib/results.lib.php';
        $status = AA_getRoundStatus($round);
        $svm = AA_checkSVM(0, $round);
        // decide whether to show club or team name
        $mergedMain = AA_checkMainRound($round);
        if ($mergedMain != 1) {
            // 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']) {
                        // show link to rankinglist if results done
                        if ($status == $cfgRoundStatus['results_done']) {
                            $menu = new GUI_Menulist();
                            $menu->addButton("print_rankinglist.php?event={$event}&round={$round}&type=single&formaction=speaker", $GLOBALS['strRankingList']);
                            $menu->addButton("print_rankinglist.php?event={$event}&round={$round}&type=single&formaction=speaker&show_efforts=sb_pb", $GLOBALS['strRankingListEfforts']);
                            $menu->printMenu();
                            echo "<p/>";
                        }
                        $prog_mode = AA_results_getProgramMode();
                        // display all athletes
                        $sql = "\r\n            SELECT\r\n                rt.Name\r\n                , rt.Typ\r\n                , s.xSerie\r\n                , s.Bezeichnung\r\n                , s.Status\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 . "', te.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo))   \r\n                , LPAD(s.Bezeichnung,5,'0') as heatid\r\n                , st.Bestleistung\r\n                , at.xAthlet\r\n                , at.Land\r\n                , r.Status\r\n                , ss.Starthoehe\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 team AS te ON(a.xTeam = te.xTeam) \r\n                LEFT JOIN verein AS v ON (v.xVerein = at.xVerein)\r\n                LEFT JOIN rundentyp_" . $_COOKIE['language'] . " AS rt ON rt.xRundentyp = r.xRundentyp\r\n            WHERE \r\n                r.xRunde = {$round}   \r\n            ORDER BY\r\n                heatid\r\n                , ss.Position";
                        $result = mysql_query($sql);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $h = 0;
                            $i = 0;
                            $current_athlete = false;
                            $curr_class = '';
                            $resTable = new GUI_HighResultTable($round, $layout, $status);
                            while ($row = mysql_fetch_row($result)) {
                                /*
                                 *  Heat headerline
                                 */
                                if ($h != $row[2]) {
                                    $h = $row[2];
                                    // keep heat ID
                                    if (is_null($row[0])) {
                                        // only one round
                                        $title = "{$strFinalround}  {$row['3']}";
                                    } else {
                                        // more than one round
                                        $title = "{$row['0']}: {$row['1']}{$row['3']}";
                                    }
                                    $c = 0;
                                    if ($status == $cfgRoundStatus['results_done']) {
                                        $c = 1;
                                        // increment colspan to include ranking
                                    }
                                    $resTable->printHeatTitle($row[2], $row[3], $title, $row[4]);
                                    $resTable->printAthleteHeader('', $round, $row[17]);
                                }
                                // ET new heat
                                /*
                                 * Athlete data lines
                                 */
                                $rank = '';
                                $perfs = array();
                                $res = mysql_query("\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\tr.Leistung\r\n\t\t\t\t\t\t, r.Info\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tresultat as r\r\n\t\t\t\t\tWHERE r.xSerienstart = {$row['5']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\tr.xResultat DESC\r\n\t\t\t\t");
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    if ($status == $cfgRoundStatus['results_done']) {
                                        $rank = $row[7];
                                    }
                                    while ($resrow = mysql_fetch_row($res)) {
                                        $perf = AA_formatResultMeter($resrow[0]);
                                        $info = $resrow[1];
                                        $perfs[] = "{$perf} ( {$info} )";
                                    }
                                    // end loop every tech result acc. programm mode
                                    mysql_free_result($res);
                                }
                                $heatStart = AA_getCurrAthlete($row[2]);
                                if ($heatStart > 0) {
                                    if ($row[5] == $heatStart) {
                                        $curr_class = "active";
                                    }
                                } else {
                                    if (empty($perfs) && !$current_athlete) {
                                        $current_athlete = true;
                                        $curr_class = "active";
                                    }
                                }
                                $resTable->printAthleteLine($row[6], $row[8], "{$row['9']} {$row['10']}", AA_formatYearOfBirth($row[11]), $row[12], AA_formatResultMeter($row[14]), $perfs, $fett, $rank, $row[16], $row[15], $curr_class, '', $row[17], $row[18]);
                                $curr_class = "";
                            }
                            $resTable->endTable();
                            mysql_free_result($result);
                        }
                        // ET DB error
                    }
                }
            }
            // ET heat seeding done
        } else {
            AA_printErrorMsg($strErrMergedRoundSpeaker);
        }
        ?>
 
    
   <script type="text/javascript">
<!--
    window.setTimeout("updatePage()", <?php 
        echo $cfgMonitorReload * 1000;
        ?>
);

   

    function updatePage()
    {
        window.open("speaker_results.php?round=<?php 
        echo $round;
        ?>
", "main");
    }

    
</script> 
    
    
    <?php 
    }
 function AA_speaker_High($event, $round, $layout)
 {
     require './lib/cl_gui_resulttable.lib.php';
     require './config.inc.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     $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']) {
                 // show link to rankinglist if results done
                 if ($status == $cfgRoundStatus['results_done']) {
                     $menu = new GUI_Menulist();
                     $menu->addButton("print_rankinglist.php?round={$round}&type=single&formaction=speaker", $GLOBALS['strRankingList']);
                     $menu->addButton("print_rankinglist.php?round={$round}&type=single&formaction=speaker&show_efforts=sb_pb", $GLOBALS['strRankingListEfforts']);
                     $menu->printMenu();
                     echo "<p/>";
                 }
                 $prog_mode = AA_results_getProgramMode();
                 // display all athletes
                 $result = mysql_query("\r\n\t\t\tSELECT\r\n\t\t\t\trt.Name\r\n\t\t\t\t, rt.Typ\r\n\t\t\t\t, s.xSerie\r\n\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t, s.Status\r\n\t\t\t\t, ss.xSerienstart\r\n\t\t\t\t, ss.Position\r\n\t\t\t\t, ss.Rang\r\n\t\t\t\t, a.Startnummer\r\n\t\t\t\t, at.Name\r\n\t\t\t\t, at.Vorname\r\n\t\t\t\t, at.Jahrgang\r\n\t\t\t\t, v.Name\r\n\t\t\t\t, LPAD(s.Bezeichnung,5,'0') as heatid\r\n\t\t\t\t, st.Bestleistung\r\n\t\t\t\t, at.xAthlet\r\n\t\t\t\t, at.Land\r\n\t\t\tFROM\r\n\t\t\t\trunde AS r\r\n\t\t\t\t, serie AS s\r\n\t\t\t\t, serienstart AS ss\r\n\t\t\t\t, start AS st\r\n\t\t\t\t, anmeldung AS a\r\n\t\t\t\t, athlet AS at\r\n\t\t\t\t, verein AS v\r\n\t\t\tLEFT JOIN rundentyp AS rt\r\n\t\t\t\tON rt.xRundentyp = r.xRundentyp\r\n\t\t\tWHERE r.xRunde = {$round}\r\n\t\t\tAND s.xRunde = r.xRunde\r\n\t\t\tAND ss.xSerie = s.xSerie\r\n\t\t\tAND st.xStart = ss.xStart\r\n\t\t\tAND a.xAnmeldung = st.xAnmeldung\r\n\t\t\tAND at.xAthlet = a.xAthlet\r\n\t\t\tAND v.xVerein = at.xVerein\r\n\t\t\tORDER BY\r\n\t\t\t\theatid\r\n\t\t\t\t, ss.Position\r\n\t\t");
                 if (mysql_errno() > 0) {
                     // DB error
                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                 } else {
                     // initialize variables
                     $h = 0;
                     $i = 0;
                     $resTable = new GUI_HighResultTable($round, $layout, $status);
                     while ($row = mysql_fetch_row($result)) {
                         /*
                          *  Heat headerline
                          */
                         if ($h != $row[2]) {
                             $h = $row[2];
                             // keep heat ID
                             if (is_null($row[0])) {
                                 // only one round
                                 $title = "{$strFinalround}  {$row['3']}";
                             } else {
                                 // more than one round
                                 $title = "{$row['0']}: {$row['1']}{$row['3']}";
                             }
                             $c = 0;
                             if ($status == $cfgRoundStatus['results_done']) {
                                 $c = 1;
                                 // increment colspan to include ranking
                             }
                             $resTable->printHeatTitle($row[2], $row[3], $title, $row[4]);
                             $resTable->printAthleteHeader();
                         }
                         // ET new heat
                         /*
                          * Athlete data lines
                          */
                         $rank = '';
                         $perfs = array();
                         $res = mysql_query("\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\tr.Leistung\r\n\t\t\t\t\t\t, r.Info\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tresultat as r\r\n\t\t\t\t\tWHERE r.xSerienstart = {$row['5']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\tr.xResultat DESC\r\n\t\t\t\t");
                         if (mysql_errno() > 0) {
                             // DB error
                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                         } else {
                             if ($status == $cfgRoundStatus['results_done']) {
                                 $rank = $row[7];
                             }
                             while ($resrow = mysql_fetch_row($res)) {
                                 $perf = AA_formatResultMeter($resrow[0]);
                                 $info = $resrow[1];
                                 $perfs[] = "{$perf} ( {$info} )";
                             }
                             // end loop every tech result acc. programm mode
                             mysql_free_result($res);
                         }
                         $resTable->printAthleteLine($row[6], $row[8], "{$row['9']} {$row['10']}", AA_formatYearOfBirth($row[11]), $row[12], AA_formatResultMeter($row[14]), $perfs, $fett, $rank, $row[16], $row[15]);
                     }
                     $resTable->endTable();
                     mysql_free_result($result);
                 }
                 // ET DB error
             }
         }
     }
     // ET heat seeding done
 }