function AA_speaker_Tech($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);
        $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']) {
                        $temp = mysql_query("\r\n\t\t\tCREATE TABLE `temp` (\r\n  `id` int(10) NOT NULL auto_increment,\r\n  `athlet` int(10) NOT NULL default '0',\r\n  `leistung` int(11) NOT NULL default '0',\r\n  `rang` int(10) NOT NULL default '0',\r\n  PRIMARY KEY  (`id`)\r\n) TYPE=MyISAM AUTO_INCREMENT=1\r\n\t\t");
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        $sql = "\r\n            SELECT\r\n                rt.Name\r\n                , rt.Typ\r\n                , s.xSerie\r\n                , s.Bezeichnung\r\n                , s.Wind\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                , v.Name\r\n                , LPAD(s.Bezeichnung,5,'0') as heatid\r\n                , w.Windmessung\r\n                , at.xAthlet\r\n                , at.Land\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 wettkampf AS w ON (w.xWettkampf = r.xWettkampf)\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\r\n        ";
                        $temp = mysql_query($sql);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            while ($row = mysql_fetch_row($temp)) {
                                $tempsql = "SELECT\r\n\t\t\t\t\t\tMAX(r.Leistung) As maxLeistung\r\n\t\t\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['6']}";
                                $tempres = mysql_query($tempsql);
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    while ($restemp = mysql_fetch_row($tempres)) {
                                        if (!empty($restemp[0])) {
                                            mysql_query("INSERT INTO `temp` (  `athlet` , `leistung` , `rang`) \r\n\t\t\t\t                        VALUES ({$row['6']}, {$restemp['0']} , 1);");
                                            if (mysql_errno() > 0) {
                                                // DB error
                                                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                            }
                                        }
                                    }
                                }
                                mysql_free_result($tempres);
                            }
                            mysql_free_result($temp);
                        }
                        $xrang = 1;
                        $templeistung = 0;
                        $temprang = mysql_query("SELECT * FROM temp ORDER BY leistung DESC");
                        while ($rowrang = mysql_fetch_row($temprang)) {
                            if ($rowrang[2] == $templeistung) {
                                $rangieren = mysql_query("UPDATE temp SET rang = {$yrang} WHERE id={$rowrang['0']}");
                            } else {
                                $rangieren = mysql_query("UPDATE temp SET rang = {$xrang} WHERE id={$rowrang['0']}");
                                $yrang = $xrang;
                            }
                            $templeistung = $rowrang[2];
                            $xrang = $xrang + 1;
                        }
                        // if this is a combined event, rank all rounds togheter
                        $roundSQL = "";
                        if ($combined) {
                            $roundSQL = "AND s.xRunde IN (";
                            $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $event);
                            while ($row_c = mysql_fetch_array($res_c)) {
                                $roundSQL .= $row_c[0] . ",";
                            }
                            $roundSQL = substr($roundSQL, 0, -1) . ")";
                        } else {
                            $roundSQL = "AND s.xRunde = {$round}";
                        }
                        $countAthlete = 0;
                        $sql_at = "SELECT \r\n                       Count(*)\r\n                 FROM \r\n                        start AS s                      \r\n                 WHERE   \r\n                        s.xWettkampf = " . $event;
                        $result_at = mysql_query($sql_at);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        }
                        $row_at = mysql_fetch_row($result_at);
                        if (mysql_num_rows($result_at) > 0) {
                            $countAthlete = $row_at[0];
                        }
                        // 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/>";
                        }
                        $svm = AA_checkSVM(0, $round);
                        // decide whether to show club or team name
                        $prog_mode = AA_results_getProgramMode();
                        // find current athlete (show yellow) when more than one attempt
                        $roundSQL_C = substr($roundSQL, 4);
                        $sql_curr = "SELECT \r\n                    count( * ) , \r\n                    ss.xSerienstart,\r\n                    if (ss.Position2 > 0, if (ss.Position3 > 0, ss.Position3, ss.Position2) , ss.Position ) as posOrder,\r\n                    s.MaxAthlet,\r\n                    ss.Position2,\r\n                    ss.Position3\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_C}  \r\n              GROUP BY ss.xSerienstart\r\n              ORDER BY posOrder ";
                        $res_curr = mysql_query($sql_curr);
                        if (mysql_errno() > 0) {
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            $ss = 0;
                            $keep_ss = 0;
                            // current athlete to show yellow
                            $keep_ss_first = 0;
                            // first athlete is current when all have same count of attempts
                            $c = 0;
                            $z = 0;
                            $maxAthlete = 0;
                            while ($row_curr = mysql_fetch_row($res_curr)) {
                                if ($z > 0 && $z == $maxAthlete) {
                                    break;
                                }
                                if ($c > 0) {
                                    if ($row_curr[0] < $c) {
                                        $keep_ss_save = $keep_ss;
                                        $keep_ss = $row_curr[1];
                                        break;
                                    }
                                }
                                $c = $row_curr[0];
                                $ss = $row_curr[1];
                                if ($z == 0) {
                                    $keep_ss_first = $row_curr[1];
                                    if ($row_curr[4] > 0 || $row_curr[5] > 0) {
                                        $maxAthlete = $row_curr[3];
                                    }
                                }
                                $z++;
                            }
                        }
                        if ($prog_mode == 0) {
                            if ($keep_ss == 0 && $r < $r_attempts) {
                                $keep_ss = $keep_ss_first;
                            } else {
                                if ($r < $r_attempts) {
                                    $keep_ss = $keep_ss_save;
                                }
                            }
                        } else {
                            if ($keep_ss == 0 && $z % $countAthlete == 0) {
                                $keep_ss = $keep_ss_first;
                            }
                        }
                        $arg = isset($_GET['arg']) ? $_GET['arg'] : (isset($_COOKIE['sort_speaker']) ? $_COOKIE['sort_speaker'] : 'pos');
                        setcookie('sort_speaker', $arg, time() + 2419200);
                        // display all athletes
                        if ($arg == "nbr" && !$relay) {
                            $argument = "a.Startnummer";
                            $img_nbr = "img/sort_act.gif";
                        } else {
                            if ($arg == "pos") {
                                $argument = "ss.Position";
                                $img_pos = "img/sort_act.gif";
                            } else {
                                if ($arg == "name") {
                                    $argument = "at.Name, at.Vorname";
                                    $img_name = "img/sort_act.gif";
                                } else {
                                    if ($arg == "club") {
                                        if ($svm) {
                                            $argument = "te.Name, a.Startnummer";
                                        } else {
                                            $argument = "v.Name, a.Startnummer";
                                        }
                                        $img_club = "img/sort_act.gif";
                                    } else {
                                        if ($arg == "perf") {
                                            $argument = "st.Bestleistung, ss.Position";
                                            $img_perf = "img/sort_act.gif";
                                        } else {
                                            if ($arg == "rang") {
                                                $argument = "t.rang, ss.Position";
                                                $img_rang = "img/sort_act.gif";
                                            } else {
                                                if ($relay == FALSE) {
                                                    // single event
                                                    $argument = "ss.Position";
                                                    $img_pos = "img/sort_act.gif";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $sql = "\r\n            SELECT\r\n                rt.Name\r\n                , rt.Typ\r\n                , s.xSerie\r\n                , s.Bezeichnung\r\n                , s.Wind\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                , w.Windmessung\r\n                , st.Bestleistung\r\n                , at.xAthlet\r\n                , at.Land\r\n                , t.rang\r\n                , r.xRunde\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 te ON(a.xTeam = te.xTeam) \r\n                LEFT JOIN wettkampf AS w ON (w.xWettkampf = r.xWettkampf)\r\n                LEFT JOIN temp AS t ON (t.athlet = ss.xSerienstart)\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 s.xSerie, \r\n                " . $argument . "\r\n        ";
                        $result = mysql_query($sql);
                        if (mysql_errno() > 0) {
                            // DB error
                            AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                        } else {
                            // initialize variables
                            $h = 0;
                            $i = 0;
                            $r = 0;
                            $resTable = new GUI_TechResultTable($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;
                                    $c++;
                                    // increment colspan to include ranking
                                    $resTable->printHeatTitle($row[2], $row[3], $title, $row[5]);
                                    $resTable->printAthleteHeader('', $row[20]);
                                }
                                // ET new heat
                                /*
                                 * Athlete data lines
                                 */
                                $perfs = array();
                                $fett = array();
                                $sql = "SELECT\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['6']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\tr.xResultat";
                                $res = mysql_query($sql);
                                if (mysql_errno() > 0) {
                                    // DB error
                                    AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                } else {
                                    while ($resrow = mysql_fetch_row($res)) {
                                        $sql2 = "SELECT\r\n\t\t\t\t\t\tleistung\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\ttemp\r\n\t\t\t\t\t\tWHERE athlet = {$row['6']}";
                                        $res2 = mysql_query($sql2);
                                        while ($row2 = mysql_fetch_row($res2)) {
                                            if ($row2[0] == $resrow[0]) {
                                                $fett[] = 1;
                                            } else {
                                                $fett[] = 0;
                                            }
                                            $perf = AA_formatResultMeter($resrow[0]);
                                            if ($row[15] == 1) {
                                                // with wind
                                                $info = $resrow[1];
                                                $perfs[] = "{$perf} ( {$info} )";
                                            } else {
                                                $perfs[] = "{$perf}";
                                            }
                                        }
                                    }
                                    // end loop every tech result acc. programm mode
                                    mysql_free_result($res);
                                }
                                //print_r($perfs);
                                if ($keep_ss > 0) {
                                    if ($keep_ss == $row[6]) {
                                        $curr_class = "active";
                                    }
                                } else {
                                    if (empty($perfs) && !$current_athlete) {
                                        $current_athlete = true;
                                        $curr_class = "active";
                                    }
                                }
                                $resTable->printAthleteLine($row[7], $row[9], "{$row['10']} {$row['11']}", AA_formatYearOfBirth($row[12]), $row[13], AA_formatResultMeter($row[16]), $perfs, $fett, $row[19], $row[18], $row[17], $curr_class);
                                $curr_class = "";
                            }
                            $resTable->endTable();
                            mysql_free_result($result);
                        }
                        // ET DB error
                    }
                }
            }
            // ET heat seeding done
            $temp = mysql_query("\r\n\t\tDROP TABLE IF EXISTS `temp`\r\n\t");
        } 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 
    }
Пример #2
0
 function AA_regie_Tech($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';
     require './lib/cl_gui_page.lib.php';
     require './lib/cl_gui_menulist.lib.php';
     $status = AA_getRoundStatus($round);
     $eval = AA_results_getEvaluationType($round);
     $combined = AA_checkCombined(0, $round);
     $prog_mode = AA_results_getProgramMode();
     // if this is a combined event, rank all rounds togheter
     $roundSQL = "";
     $roundSQL2 = "";
     if ($combined) {
         $roundSQL = "AND s.xRunde IN (";
         $roundSQL2 = "AND s.xRunde IN (";
         $res_c = mysql_query("SELECT xRunde FROM runde WHERE xWettkampf = " . $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 = "AND s.xRunde = {$round}";
         $roundSQL2 = "AND s.xRunde = {$round}";
     }
     $result = mysql_query("SELECT COUNT(*), ru.Versuche" . " FROM resultat AS r" . ", serienstart AS ss" . ", serie AS s" . ", runde AS ru" . " WHERE r.xSerienstart = ss.xSerienstart" . " AND ss.xSerie = s.xSerie" . " AND s.xRunde = ru.xRunde" . " {$roundSQL2} " . " GROUP BY r.xSerienstart" . " ORDER BY 1 DESC");
     $row = mysql_fetch_row($result);
     $r = $row[0];
     // max. attempts
     mysql_query("\r\n                LOCK TABLES\r\n                    resultat READ\r\n                    , serie READ\r\n                    , start READ \r\n                    , resultat as r READ\r\n                    , serie as s READ\r\n                    , start as st READ \r\n                    , serienstart as ss READ   \r\n                    , wettkampf as w READ\r\n                    , serienstart READ\r\n                    , anmeldung as a READ \r\n                    , athlet as at READ \r\n                    , verein as v READ \r\n                    , rundentyp as rt READ   \r\n                    , tempTech WRITE\r\n                    , tempTech as t READ  \r\n            ");
     mysql_query("DROP TABLE IF EXISTS `tempTech`");
     // temporary table
     // 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 TEMPORARY TABLE IF NOT EXISTS tempTech (\r\n                    xSerienstart int(11)\r\n                    , xSerie int(11)\r\n                    , rang int(11)\r\n                     , position 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 {
         $result = mysql_query("\r\n                    SELECT\r\n                        r.Leistung\r\n                        , r.Info\r\n                        , ss.xSerienstart\r\n                        , ss.xSerie\r\n                        , ss.Position\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                        r.Leistung >= 0\r\n                        {$roundSQL} \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 tempTech VALUES({$row['2']},{$row['3']}, 0, {$row['4']}";
                     $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                            tempTech\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                            tempTech\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 + 3];
                     $wind[$i] = $row[2 * $i + 4];
                 }
                 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 tempTech 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);
         }
     }
     // find current athlete (show yellow) when more than one attempt
     $roundSQL_C = substr($roundSQL, 4);
     $sql_curr = "SELECT \r\n                    count( * ) , \r\n                    ss.xSerienstart,\r\n                    if (ss.Position2 > 0, if (ss.Position3 > 0, ss.Position3, ss.Position2) , ss.Position ) as posOrder,\r\n                    s.MaxAthlet,\r\n                    ss.Position2,\r\n                    ss.Position3\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_C}  \r\n              GROUP BY ss.xSerienstart\r\n              ORDER BY posOrder ";
     $res_curr = mysql_query($sql_curr);
     if (mysql_errno() > 0) {
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $ss = 0;
         $keep_ss = 0;
         // current athlete to show yellow
         $keep_ss_first = 0;
         // first athlete is current when all have same count of attempts
         $c = 0;
         $z = 0;
         $maxAthlete = 0;
         while ($row_curr = mysql_fetch_row($res_curr)) {
             if ($z > 0 && $z == $maxAthlete) {
                 break;
             }
             if ($c > 0) {
                 if ($row_curr[0] < $c) {
                     $keep_ss = $row_curr[1];
                     break;
                 }
             }
             $c = $row_curr[0];
             $ss = $row_curr[1];
             if ($z == 0) {
                 $keep_ss_first = $row_curr[1];
                 if ($row_curr[4] > 0 || $row_curr[5] > 0) {
                     $maxAthlete = $row_curr[3];
                 }
             }
             $z++;
         }
     }
     $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 == "nbr" && !$relay) {
         $argument = "a.Startnummer";
         $img_nbr = "img/sort_act.gif";
     } else {
         if ($arg == "pos") {
             $argument = "ss.Position";
             $img_pos = "img/sort_act.gif";
         } else {
             if ($arg == "name") {
                 $argument = "at.Name, at.Vorname";
                 $img_name = "img/sort_act.gif";
             } else {
                 if ($arg == "club") {
                     $argument = "v.Name, a.Startnummer";
                     $img_club = "img/sort_act.gif";
                 } else {
                     if ($arg == "perf") {
                         $argument = "st.Bestleistung, ss.Position";
                         $img_perf = "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.Wind\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, w.Windmessung\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\t\t, t.rang\r\n                , if (t.rang > 0,  t.rang, 999999) as orderRang\r\n\t\t\tFROM\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 wettkampf AS w ON (w.xWettkampf = r.xWettkampf)  \r\n\t\t\t\tLEFT JOIN tempTech 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}     \r\n\t\t\tORDER BY s.xSerie, \r\n\t\t\t\t" . $argument . "\r\n\t\t");
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         // initialize variables
         $h = 0;
         $i = 0;
         $r = 0;
         $current_athlete = false;
         $curr_class = '';
         $resTable = new GUI_TechResultTable($round, $layout, $status);
         $resTable->printHeatTitleRegie($cat, $disc);
         if ($maxAthlete > 0) {
             $c_athl = $maxAthlete;
             // maximum of athletes for next attempts
         } else {
             $c_athl = mysql_num_rows($result);
             // number of all athletes
         }
         if ($z == $c_athl && $keep_ss == 0) {
             // all athletes same count of attempts then show first as current athlete
             $keep_ss = $keep_ss_first;
         }
         while ($row = mysql_fetch_row($result)) {
             /*
              *  Heat headerline
              */
             if ($h != $row[2]) {
                 $current_athlete = false;
                 $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;
                 $c++;
                 // increment colspan to include ranking
                 $resTable->printHeatTitle($row[2], $row[3], $title, $row[5], 'regie');
                 $resTable->printAthleteHeader('regie', $round);
             }
             // ET new heat
             /*
              * Athlete data lines
              */
             $perfs = array();
             $fett = array();
             $sql = "SELECT\r\n\t\t\t\t\t\t    r.Leistung\r\n\t\t\t\t\t\t    , r.Info\r\n                            , r.xSerienstart\r\n\t\t\t\t        FROM\r\n\t\t\t\t\t\t    resultat AS r\r\n\t\t\t\t\t    WHERE \r\n                            r.xSerienstart = {$row['6']}\r\n\t\t\t\t\t    ORDER BY\r\n\t\t\t\t\t        r.xResultat";
             $res = mysql_query($sql);
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 while ($resrow = mysql_fetch_row($res)) {
                     $sql2 = "SELECT\r\n\t\t\t\t\t\t                max(r.Leistung)\r\n\t\t\t\t\t\t         FROM\r\n\t\t\t\t\t\t                resultat AS r \r\n\t\t\t\t\t\t         WHERE \r\n                                        r.xSerienstart = {$row['6']}";
                     $res2 = mysql_query($sql2);
                     $row2 = mysql_fetch_row($res2);
                     if ($row2[0] == $resrow[0]) {
                         $fett[] = 1;
                     } else {
                         $fett[] = 0;
                     }
                     $perf = AA_formatResultMeter($resrow[0]);
                     if ($row[15] == 1) {
                         // with wind
                         $info = $resrow[1];
                         $perfs[] = "{$perf} ( {$info} )";
                     } else {
                         $perfs[] = "{$perf}";
                     }
                 }
                 // end loop every tech result acc. programm mode
                 mysql_free_result($res);
             }
             //print_r($perfs);
             if ($row[19] == 0) {
                 $row[19] = '';
             }
             if ($prog_mode == 2) {
                 if ($keep_ss > 0) {
                     if ($keep_ss == $row[6]) {
                         $curr_class = "active";
                     }
                 } else {
                     if (empty($perfs) && !$current_athlete) {
                         $current_athlete = true;
                         $curr_class = "active";
                     }
                 }
             }
             $resTable->printAthleteLine($row[7], $row[9], "{$row['10']} {$row['11']}", '', '', AA_formatResultMeter($row[16]), $perfs, $fett, $row[19], '', $row[17], $curr_class, 'regie');
             $curr_class = "";
         }
         $resTable->endTable();
         mysql_free_result($result);
     }
     // ET DB error
     mysql_query("UNLOCK TABLES");
     $temp = mysql_query("DROP TABLE IF EXISTS `tempTech` ");
 }
 function AA_speaker_Tech($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']) {
                 $temp = mysql_query("\r\n\t\t\tCREATE TABLE `temp` (\r\n  `id` int(10) NOT NULL auto_increment,\r\n  `athlet` int(10) NOT NULL default '0',\r\n  `leistung` int(11) NOT NULL default '0',\r\n  `rang` int(10) NOT NULL default '0',\r\n  PRIMARY KEY  (`id`)\r\n) TYPE=MyISAM AUTO_INCREMENT=1\r\n\t\t");
                 if (mysql_errno() > 0) {
                     // DB error
                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                 }
                 $temp = 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.Wind\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, w.Windmessung\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\t\t, wettkampf AS w\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 w.xWettkampf = r.xWettkampf\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 {
                     while ($row = mysql_fetch_row($temp)) {
                         $tempsql = "SELECT\r\n\t\t\t\t\t\tMAX(r.Leistung) As maxLeistung\r\n\t\t\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['6']}";
                         $tempres = mysql_query($tempsql);
                         if (mysql_errno() > 0) {
                             // DB error
                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                         } else {
                             while ($restemp = mysql_fetch_row($tempres)) {
                                 mysql_query("INSERT INTO `temp` ( `id` , `athlet` , `leistung` , `rang`) \r\n\t\t\t\tVALUES ('', '{$row['6']}', '{$restemp['0']}' , '1');");
                             }
                         }
                         mysql_free_result($tempres);
                     }
                     mysql_free_result($temp);
                 }
                 $xrang = 1;
                 $templeistung = 0;
                 $temprang = mysql_query("SELECT * FROM temp ORDER BY leistung DESC");
                 while ($rowrang = mysql_fetch_row($temprang)) {
                     if ($rowrang[2] == $templeistung) {
                         $rangieren = mysql_query("UPDATE temp SET rang = {$yrang} WHERE id={$rowrang['0']}");
                     } else {
                         $rangieren = mysql_query("UPDATE temp SET rang = {$xrang} WHERE id={$rowrang['0']}");
                         $yrang = $xrang;
                     }
                     $templeistung = $rowrang[2];
                     $xrang = $xrang + 1;
                 }
                 // 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();
                 $arg = isset($_GET['arg']) ? $_GET['arg'] : (isset($_COOKIE['sort_speakres']) ? $_COOKIE['sort_speakres'] : 'pos');
                 setcookie('sort_speakres', $arg, time() + 2419200);
                 // display all athletes
                 if ($arg == "nbr" && !$relay) {
                     $argument = "a.Startnummer";
                     $img_nbr = "img/sort_act.gif";
                 } else {
                     if ($arg == "pos") {
                         $argument = "ss.Position";
                         $img_pos = "img/sort_act.gif";
                     } else {
                         if ($arg == "name") {
                             $argument = "at.Name, at.Vorname";
                             $img_name = "img/sort_act.gif";
                         } else {
                             if ($arg == "club") {
                                 $argument = "v.Name, a.Startnummer";
                                 $img_club = "img/sort_act.gif";
                             } else {
                                 if ($arg == "perf") {
                                     $argument = "st.Bestleistung, ss.Position";
                                     $img_perf = "img/sort_act.gif";
                                 } else {
                                     if ($arg == "rang") {
                                         $argument = "t.rang, 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.Wind\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, w.Windmessung\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\t\t, t.rang\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\t\t, wettkampf AS w\r\n\t\t\t\t, temp AS t\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 w.xWettkampf = r.xWettkampf\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\tAND t.athlet = ss.xSerienstart\r\n\t\t\tORDER BY s.xSerie, \r\n\t\t\t\t" . $argument . "\r\n\t\t");
                 if (mysql_errno() > 0) {
                     // DB error
                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                 } else {
                     // initialize variables
                     $h = 0;
                     $i = 0;
                     $r = 0;
                     $resTable = new GUI_TechResultTable($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;
                             $c++;
                             // increment colspan to include ranking
                             $resTable->printHeatTitle($row[2], $row[3], $title, $row[5]);
                             $resTable->printAthleteHeader();
                         }
                         // ET new heat
                         /*
                          * Athlete data lines
                          */
                         $perfs = array();
                         $fett = array();
                         $sql = "SELECT\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['6']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\tr.xResultat";
                         $res = mysql_query($sql);
                         //echo $sql;
                         if (mysql_errno() > 0) {
                             // DB error
                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                         } else {
                             while ($resrow = mysql_fetch_row($res)) {
                                 $sql2 = "SELECT\r\n\t\t\t\t\t\tleistung\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\ttemp\r\n\t\t\t\t\t\tWHERE athlet = {$row['6']}";
                                 $res2 = mysql_query($sql2);
                                 while ($row2 = mysql_fetch_row($res2)) {
                                     if ($row2[0] == $resrow[0]) {
                                         $fett[] = 1;
                                     } else {
                                         $fett[] = 0;
                                     }
                                     $perf = AA_formatResultMeter($resrow[0]);
                                     if ($row[15] == 1) {
                                         // with wind
                                         $info = $resrow[1];
                                         $perfs[] = "{$perf} ( {$info} )";
                                     } else {
                                         $perfs[] = "{$perf}";
                                     }
                                 }
                             }
                             // end loop every tech result acc. programm mode
                             mysql_free_result($res);
                         }
                         //print_r($perfs);
                         $resTable->printAthleteLine($row[7], $row[9], "{$row['10']} {$row['11']}", AA_formatYearOfBirth($row[12]), $row[13], AA_formatResultMeter($row[16]), $perfs, $fett, $row[19], $row[18], $row[17]);
                     }
                     $resTable->endTable();
                     mysql_free_result($result);
                 }
                 // ET DB error
             }
         }
     }
     // ET heat seeding done
     $temp = mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `temp`\r\n\t\t");
 }