function AA_regie_Track($event, $round, $layout, $cat, $disc)
 {
     require './lib/cl_gui_menulist.lib.php';
     require './lib/cl_gui_resulttable.lib.php';
     require './config.inc.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     $relay = AA_checkRelay($event);
     // check, if this is a relay event
     $status = AA_getRoundStatus($round);
     $combined = AA_checkCombined(0, $round);
     $eval = AA_results_getEvaluationType($round);
     if ($eval == $cfgEvalType[$strEvalTypeAll] || $eval == $cfgEvalType[$strEvalTypeHeat] && isset($eventType['club'])) {
         // eval all heats together
         $heatorder = "";
     } else {
         // default: rank results per heat
         $heatorder = "serie.xSerie, ";
     }
     // show qualification info if another round follows
     $nextRound = AA_getNextRound($event, $round);
     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) {
             }
             echo "{$strQualification}: {$row['0']} {$strQualifyTop}, {$row['1']} {$strQualifyPerformance}";
             echo "<p/>";
         }
         // ET DB error
         mysql_free_result($result);
     }
     // ET next 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                     , runde as r 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                    , anmeldung as a READ \r\n                    , athlet as at READ \r\n                    , verein as v READ \r\n                    , anlage as an READ \r\n                    , rundentyp as rt READ   \r\n                    , tempTrack WRITE\r\n            ");
     mysql_query("TRUNCATE TABLE tempTrack");
     // 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 = {$event}");
         while ($row_c = mysql_fetch_array($res_c)) {
             $roundSQL .= $row_c[0] . ",";
         }
         $roundSQL = substr($roundSQL, 0, -1) . ")";
     } else {
         $roundSQL = "WHERE serie.xRunde = {$round}";
     }
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $sql = "SELECT DISTINCT \r\n                           resultat.Leistung, \r\n                           serienstart.xSerienstart, \r\n                           serienstart.xSerie, \r\n                           serienstart.xStart, \r\n                           serie.Wind \r\n                     FROM \r\n                           resultat \r\n                           LEFT JOIN serienstart USING(xSerienstart) \r\n                           LEFT JOIN serie USING(xSerie) \r\n                           " . $roundSQL . " \r\n                     ORDER BY " . $heatorder . "\r\n                            resultat.Leistung ASC;";
         $result = mysql_query($sql);
         $heat = 0;
         $perf = 0;
         $perfRounded = 0;
         $i = 0;
         $rank = 0;
         while ($row = mysql_fetch_row($result)) {
             // check on codes < 0
             if ($row[0] < 0) {
                 mysql_query("INSERT INTO tempTrack SET" . " Leistung = " . $row[0] . " , xSerienstart = " . $row[1] . " , xSerie = " . $row[2] . " , rang = 0");
             } 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;
                         $perfRounded = 0;
                     }
                 }
                 $i++;
                 // increment ranking
                 if ($perf < $row[0]) {
                     // compare with previous performance
                     $rank = $i;
                     // next rank (only if not same performance)
                 }
                 mysql_query("INSERT INTO tempTrack SET " . " Leistung = " . $row[0] . " , xSerienstart = " . $row[1] . " , xSerie = " . $row[2] . " , rang = " . $rank);
                 if (mysql_errno() > 0) {
                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                 }
                 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($temp);
         }
         // display all athletes
         if ($relay == FALSE) {
             // single event
             $query = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tr.Bahnen\r\n\t\t\t\t\t, rt.Name\r\n\t\t\t\t\t, rt.Typ\r\n\t\t\t\t\t, s.xSerie\r\n\t\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t\t, s.Wind\r\n\t\t\t\t\t, s.Film\r\n\t\t\t\t\t, s.Status\r\n\t\t\t\t\t, ss.xSerienstart\r\n\t\t\t\t\t, ss.Position\r\n\t\t\t\t\t, ss.Rang\r\n\t\t\t\t\t, ss.Qualifikation\r\n\t\t\t\t\t, a.Startnummer\r\n\t\t\t\t\t, at.Name\r\n\t\t\t\t\t, at.Vorname\r\n\t\t\t\t\t, at.Jahrgang\r\n\t\t\t\t\t, v.Name\r\n\t\t\t\t\t, LPAD(s.Bezeichnung,5,'0') as heatid\r\n\t\t\t\t\t, at.Land\r\n\t\t\t\t\t, st.Bestleistung\r\n\t\t\t\t\t, at.xAthlet\r\n                    , t.rang  \r\n                    , if (ss.Rang = 0, 999999, ss.Rang) as orderRang    \r\n\t\t\t\tFROM\r\n\t\t\t\t\trunde AS r\r\n\t\t\t\t\tLEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n\t\t\t\t\tLEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n\t\t\t\t\tLEFT JOIN start AS st ON (st.xStart = ss.xStart)\r\n\t\t\t\t\tLEFT JOIN anmeldung AS a ON (a.xAnmeldung = st.xAnmeldung)\r\n\t\t\t\t\tLEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n\t\t\t\t\tLEFT JOIN verein AS v  ON (v.xVerein = at.xVerein)\r\n                    LEFT JOIN tempTrack AS t ON (t.xSerienstart = ss.xSerienstart)  \r\n\t\t\t\t    LEFT JOIN rundentyp AS rt ON rt.xRundentyp = r.xRundentyp\r\n\t\t\t\t    LEFT JOIN anlage AS an ON an.xAnlage = s.xAnlage\r\n\t\t\t\tWHERE \r\n                    r.xRunde = {$round}    \t\t\t\t\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\theatid\r\n\t\t\t\t\t, orderRang\r\n\t\t\t";
         } else {
             // relay event
             $query = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tr.Bahnen\r\n\t\t\t\t\t, rt.Name\r\n\t\t\t\t\t, rt.Typ\r\n\t\t\t\t\t, s.xSerie\r\n\t\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t\t, s.Wind\r\n\t\t\t\t\t, s.Film\r\n\t\t\t\t\t, s.Status\r\n\t\t\t\t\t, ss.xSerienstart\r\n\t\t\t\t\t, ss.Position\r\n\t\t\t\t\t, ss.Rang\r\n\t\t\t\t\t, ss.Qualifikation\r\n\t\t\t\t\t, sf.Name\r\n\t\t\t\t\t, v.Name\r\n\t\t\t\t\t, LPAD(s.Bezeichnung,5,'0') as heatid\r\n\t\t\t\t\t, r.xRunde\r\n\t\t\t\t\t, st.xStart\r\n                    , t.rang \r\n                    , if (ss.Rang = 0, 999999, ss.Rang) as orderRang    \r\n\t\t\t\tFROM\r\n\t\t\t\t\trunde AS r\r\n\t\t\t\t\tLEFT JOIN serie AS s ON (s.xRunde = r.xRunde)\r\n\t\t\t\t\tLEFT JOIN serienstart AS ss  ON (ss.xSerie = s.xSerie )\r\n\t\t\t\t\tLEFT JOIN start AS st ON (st.xStart = ss.xStart) \r\n\t\t\t\t\tLEFT JOIN staffel AS sf ON (sf.xStaffel = st.xStaffel) \r\n\t\t\t\t\tLEFT JOIN verein AS v ON (v.xVerein = sf.xVerein) \r\n                    LEFT JOIN tempTrack AS t ON (t.xSerienstart = ss.xSerienstart)   \r\n\t\t\t\t    LEFT JOIN rundentyp AS rt ON rt.xRundentyp = r.xRundentyp\r\n\t\t\t\t    LEFT JOIN anlage AS an ON an.xAnlage = s.xAnlage\r\n\t\t\t\tWHERE \r\n                    r.xRunde = {$round}  \t\t\t\t\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\theatid\r\n\t\t\t\t\t, orderRang\r\n\t\t\t";
         }
         $result = mysql_query($query);
         if (mysql_errno() > 0) {
             // DB error
             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
         } else {
             // initialize variables
             $h = 0;
             // heat counter
             $p = 0;
             // position counter (to evaluate empty heats
             $tracks = 0;
             $resTable = new GUI_TrackResultTable($round, $layout, $status, $nextRound);
             $resTable->printHeatTitleRegie($cat, $disc);
             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) {
                         $resTable->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} {$row['4']}";
                     } else {
                         // more than one round
                         $title = "{$row['1']}: {$row['2']}{$row['4']}";
                     }
                     // increment colspan to include ranking and qualification
                     $c = 0;
                     if ($status == $cfgRoundStatus['results_done']) {
                         $c++;
                         if ($nextRound > 0) {
                             $c++;
                         }
                     }
                     $resTable->printHeatTitle($row[3], $row[4], $title, $row[7], $row[6], $row[5], 'regie', $relay);
                     if ($relay == FALSE) {
                         // athlete display
                         $resTable->printAthleteHeader('regie');
                     } else {
                         // relay display
                         $resTable->printRelayHeader('regie');
                     }
                 }
                 // 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 = $resTable->printEmptyTracks($p, $row[9] - 1, 6 + $c);
                     }
                 }
                 // ET empty tracks
                 /*
                  * Athlete/Relay data lines
                  */
                 // get performance
                 $perf = '';
                 $perfRounded = '';
                 $res = mysql_query("\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\trs.xResultat\r\n\t\t\t\t\t\t, rs.Leistung\r\n\t\t\t\t\t\t, rs.Info\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tresultat AS rs\r\n\t\t\t\t\tWHERE rs.xSerienstart = {$row['8']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\trs.Leistung ASC\r\n\t\t\t\t");
                 if (mysql_errno() > 0) {
                     // DB error
                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                 } else {
                     $resrow = mysql_fetch_row($res);
                     if ($resrow != NULL) {
                         // result found
                         $perf = AA_formatResultTime($resrow[1]);
                         $perfRounded = AA_formatResultTime($resrow[1], true);
                     }
                     mysql_free_result($res);
                 }
                 // ET DB error
                 // print lines
                 if ($relay == FALSE) {
                     $resTable->printAthleteLine($row[9], $row[12], "{$row['13']} {$row['14']}", '', '', AA_formatResultTime($row[19], true), $perfRounded, $row[10], $row[11], '', $row[20], 'regie', $row[21]);
                 } else {
                     // relay
                     // get Athletes
                     $arrAthletes = array();
                     $sql = "SELECT at.Vorname, at.Name FROM\r\n\t\t\t\t\t\t\t\tstaffelathlet as sfat\r\n\t\t\t\t\t\t\t\tLEFT JOIN start as st ON sfat.xAthletenstart = st.xStart\r\n\t\t\t\t\t\t\t\tLEFT JOIN anmeldung as a USING(xAnmeldung)\r\n\t\t\t\t\t\t\t\tLEFT JOIN athlet as at USING(xAthlet)\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tsfat.xStaffelstart = {$row['16']}\r\n\t\t\t\t\t\t\tAND\tsfat.xRunde = {$row['15']}\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\tsfat.Position";
                     $res_at = mysql_query($sql);
                     if (mysql_errno() > 0) {
                         // DB error
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         while ($row_at = mysql_fetch_array($res_at)) {
                             $arrAthletes[] = array($row_at[1], $row_at[0]);
                         }
                     }
                     $arrAthletes = count($arrAthletes) > 0 ? $arrAthletes : 0;
                     $resTable->printRelayLine($row[9], $row[12], $row[13], $perfRounded, $row[10], $row[11], $arrAthletes, 'regie', $row[17]);
                 }
             }
             // 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++;
                     $resTable->printEmptyTracks($p, $tracks, 6 + $c);
                 }
             }
             // ET track disciplines
             $resTable->endTable();
             mysql_free_result($result);
         }
         // ET DB error
     }
     mysql_query("UNLOCK TABLES");
 }
 function AA_rankinglist_Combined($category, $formaction, $break, $cover, $sepu23, $cover_timing = false, $date = '%', $disc_nr, $catFrom, $catTo, $ukc)
 {
     require './lib/cl_gui_page.lib.php';
     require './lib/cl_print_page.lib.php';
     require './lib/cl_export_page.lib.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     require './config.inc.php';
     if (AA_connectToDB() == FALSE) {
         // invalid DB connection
         return;
         // abort
     }
     if (AA_checkMeetingID() == FALSE) {
         // no meeting selected
         return;
         // abort
     }
     $contestcat = " ";
     if (!empty($category)) {
         // show every category
         $contestcat = " AND w.xKategorie = {$category}";
     }
     if ($catFrom > 0) {
         $getSortCat = AA_getSortCat($catFrom, $catTo);
         if ($getSortCat[0]) {
             if ($catTo > 0) {
                 $contestcat = " AND k.Anzeige >=" . $getSortCat[$catFrom] . " AND k.Anzeige <=" . $getSortCat[$catTo] . " ";
             } else {
                 $contestcat = " AND k.Anzeige =" . $getSortCat[$catFrom] . " ";
             }
         }
     }
     $GroupByUkc = "";
     if ($ukc) {
         $checkyear = date('Y') - 16;
         $min_age = date('Y') - 7;
         $selection = " AND at.Jahrgang > {$checkyear} AND (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") ";
         $sql_leftjoin = " LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (w.xDisziplin = d.xDisziplin) ";
         $order = " at.Geschlecht, at.Jahrgang,  at.Name, at.Vorname,  d.Anzeige";
         $disc_nr = 3;
     } else {
         $selection = " AND w.Mehrkampfcode > 0 ";
         $sql_leftjoin = " LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (w.Mehrkampfcode = d.Code)";
         $order = " k.Anzeige , w.Mehrkampfcode , ka.Alterslimite DESC";
     }
     $dCode = 0;
     if ($ukc) {
         $mk = ",0";
     } else {
         $mk = ",w.Mehrkampfcode";
     }
     // get athlete info per contest category
     $sql1 = "SELECT DISTINCT \r\n        a.xAnmeldung\r\n        , at.Name\r\n        , at.Vorname\r\n        , at.Jahrgang\r\n        , k.Name\r\n        , IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)\r\n        , IF(at.xRegion = 0, at.Land, re.Anzeige)";
     $sql2 = ", d.Name\r\n        , w.xKategorie\r\n        , ka.Code\r\n        , ka.Name\r\n        , ka.Alterslimite \r\n        , d.Code \r\n        , at.xAthlet\r\n        , at.Geschlecht               \r\n    FROM\r\n        anmeldung AS a\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 start as st ON (st.xAnmeldung = a.xAnmeldung ) \r\n        LEFT JOIN wettkampf as w  ON (w.xWettkampf = st.xWettkampf) " . $sql_leftjoin . "\r\n        LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n        LEFT JOIN kategorie AS ka ON (ka.xKategorie = a.xKategorie)     \r\n        LEFT JOIN region as re ON (at.xRegion = re.xRegion) \r\n    WHERE a.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n    " . $contestcat . " \r\n     " . $selection . " \r\n    AND st.anwesend = 0 ";
     $sqlOrder = " ORDER BY " . $order;
     $sql = $sql1 . $mk . $sql2 . $sqlOrder;
     $results = mysql_query($sql);
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $cat = '';
         $catEntry = '';
         $catEntryLimit = "";
         $u23name = "";
         $comb = 0;
         // hold combined type
         $combName = "";
         $lastTime = "";
         // hold start time of last event for print list
         $a = 0;
         $info = '';
         $points = 0;
         $sep = '';
         $rFrom = 0;
         $rTo = 0;
         $limitRank = false;
         if ($_GET['limitRank'] == "yes" && substr($formaction, 0, 6) == "export") {
             // check if ranks are limited
             if (!empty($_GET['limitRankFrom']) && !empty($_GET['limitRankTo'])) {
                 $limitRank = true;
                 $rFrom = $_GET['limitRankFrom'];
                 $rTo = $_GET['limitRankTo'];
             }
         }
         // start a new HTML display page
         if ($formaction == 'view') {
             // display page for speaker
             $list = new GUI_CombinedRankingList($_COOKIE['meeting']);
             $list->printPageTitle("{$strRankingLists} " . $_COOKIE['meeting']);
         } elseif ($formaction == "print") {
             $list = new PRINT_CombinedRankingList($_COOKIE['meeting']);
             if ($cover == true) {
                 // print cover page
                 $list->printCover($GLOBALS['strResults'], $cover_timing);
             }
         } elseif ($formaction == "exportpress") {
             $list = new EXPORT_CombinedRankingListPress($_COOKIE['meeting'], 'txt');
         } elseif ($formaction == "exportdiplom") {
             $list = new EXPORT_CombinedRankingListDiplom($_COOKIE['meeting'], 'csv');
         }
         if ($ukc) {
             while ($row = mysql_fetch_row($results)) {
                 if ($roundsUkc[$row[4]][$row[14]] == "") {
                     $roundsUkc[$row[4]][$row[14]] = 0;
                 }
                 $roundsUkc[$row[4]][$row[14]]++;
             }
             $GroupByUkc = " GROUP BY at.xAthlet ";
             $mk = ",w.Mehrkampfcode";
             $sql = $sql1 . $mk . $sql2 . $GroupByUkc . $sqlOrder;
             $results = mysql_query($sql);
         }
         while ($row = mysql_fetch_row($results)) {
             $dCode = $row[13];
             $row3_tmp = $row[3];
             if ($row3_tmp > $min_age) {
                 $row3_tmp = $min_age;
             }
             if ($ukc) {
                 if ($roundsUkc[$row[4]][$row[14]] != 3) {
                     continue;
                 }
             }
             // store previous before processing new athlete
             if ($a != $row[0] && $a > 0) {
                 $points_arr[] = $points;
                 if ($ukc) {
                     $xKatUKC = AA_getCatUkc($birthDate, $sex, true);
                     $points_arr_more_disc_all[$xKatUKC][] = $points_disc;
                 } else {
                     $points_arr_more_disc_all[$row[9]][] = $points_disc;
                 }
                 $name_arr[] = $name;
                 $year_arr[] = $year;
                 $club_arr[] = $club;
                 $info_arr[] = $info;
                 $ioc_arr[] = $ioc;
                 $x_arr[] = $a;
                 if (isset($points_disc_keep) && sizeof($points_disc_keep) < 3 && $ukc) {
                     $rank_arr[] = 0;
                 } else {
                     $rank_arr[] = $rank;
                 }
                 $info = '';
                 $points = 0;
                 $sep = '';
             }
             // print previous before processing new category
             if (!empty($cat) && (($row[4] != $cat || $row[7] != $comb) && $ukc == false || $ukc == true && $row3_tmp != $age || ($comb == 410 || $comb == 400) && $catEntry != $row[10] && $row[12] < 23 && !$bU23 && $sepu23)) {
                 $bU23 = false;
                 // set the separate flag! else it will be separated by each category
                 if (($comb == 410 || $comb == 400) && $catEntry != $row[10] && $row[12] < 23) {
                     $bU23 = true;
                 }
                 $u23name = '';
                 // set the addition for the title if this is the separated cat
                 if (($comb == 410 || $comb == 400) && $catEntryLimit < 23 && $sepu23) {
                     $u23name = " (U 23)";
                 }
                 $list->endList();
                 if ($ukc) {
                     $list->printSubTitle($catUKC . ", " . $cfgUKC_Name);
                 } else {
                     $list->printSubTitle($cat . "{$u23name}, " . $combName, "", "");
                 }
                 $list->startList();
                 $list->printHeaderLine($lastTime);
                 arsort($points_arr, SORT_NUMERIC);
                 // sort descending by points
                 $rank = 1;
                 // initialize rank
                 $r = 0;
                 // start value for ranking
                 $p = 0;
                 $no_rank = 999999;
                 $max_rank = $no_rank;
                 foreach ($points_arr as $key => $val) {
                     $r++;
                     if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                         // limit ranks if set (export)
                         continue;
                     }
                     if ($p != $val) {
                         // not same points as previous team
                         $rank = $r;
                         // next rank
                     }
                     // not set rank for invalid results
                     if (preg_match("@\\(-[1]{1}@", $info_arr[$key])) {
                         $rank = $max_rank;
                         $max_rank += 1;
                         $r--;
                     }
                     $rank_arr[$key] = $rank;
                     $p = $val;
                     // keep current points
                 }
                 asort($rank_arr, SORT_NUMERIC);
                 // sort descending by rank
                 $rank_keep = 0;
                 $key_keep = '';
                 foreach ($rank_arr as $key => $v) {
                     $val = $points_arr[$key];
                     $rank = $v;
                     if ($rank == $rank_keep) {
                         $c = 0;
                         $keep_c = 0;
                         // first rule
                         for ($i = 1; $i <= sizeof($points_disc); $i++) {
                             if ($points_arr_more_disc_all[$xKat][$key_keep][$i] > $points_arr_more_disc_all[$xKat][$key][$i]) {
                                 $keep_c++;
                             } else {
                                 $c++;
                             }
                         }
                         $more = ceil(sizeof($points_disc) / 2);
                         if (sizeof($points_disc) % 2 == 0) {
                             // combined with even number discs
                             $more++;
                         }
                         if ($keep_c >= $more && $keep_c > $c) {
                             $rank_arr[$key]++;
                         } else {
                             if ($c >= $more && $c > $keep_c) {
                                 $rank_arr[$key_keep]++;
                             } else {
                                 // second rule
                                 // check the best points of the highest points of discipline
                                 $k = AA_get_AthletBestPointDisc($points_arr_more_disc_all[$xKat][$key_keep], $points_arr_more_disc_all[$xKat][$key], $key_keep, $key);
                                 if ($k != 0) {
                                     $rank_arr[$k]++;
                                 }
                                 // if $k is 0, all points of diszipline are the same -->   athletes with same rank
                             }
                         }
                     }
                     $rank_keep = $rank;
                     $key_keep = $key;
                 }
                 asort($rank_arr, SORT_NUMERIC);
                 // sort descending by rank
                 foreach ($rank_arr as $key => $v) {
                     $val = $points_arr[$key];
                     $rank = $v;
                     if ($rank >= $no_rank) {
                         $rank = '';
                     }
                     $list->printLine($rank, $name_arr[$key], $year_arr[$key], $club_arr[$key], $val, $ioc_arr[$key]);
                     $list->printInfo($info_arr[$key]);
                     // insert points into combined top performance of entry
                     mysql_query("UPDATE anmeldung SET BestleistungMK = {$val} WHERE xAnmeldung = " . $x_arr[$key]);
                 }
                 unset($points_arr);
                 unset($name_arr);
                 unset($year_arr);
                 unset($club_arr);
                 unset($info_arr);
                 unset($ioc_arr);
                 unset($x_arr);
                 unset($rank_arr);
                 if (is_a($list, "PRINT_CombinedRankingList") && $break == 'category') {
                     // page break after category
                     $list->insertPageBreak();
                 }
             }
             $cat = $row[4];
             // keep current category
             $age = $row3_tmp;
             if ($ukc) {
                 $catUKC = AA_getCatUkc($row[3], $row[15], false);
                 $xKat = AA_getCatUkc($row[3], $row[15], true);
             } else {
                 $xKat = $row[9];
             }
             $catEntry = $row[10];
             $catEntryLimit = $row[12];
             $comb = $row[7];
             $combName = $row[8];
             if ($ukc) {
                 $order = " d.Anzeige, ru.Datum, ru.Startzeit";
                 $selectionDisc = " AND (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") ";
                 $selectionMk = '';
             } else {
                 $order = " w.Mehrkampfreihenfolge ASC, ru.Datum, ru.Startzeit";
                 $selectionMk = " AND w.Mehrkampfcode = " . $row[7];
                 $selectionDisc = '';
             }
             // events
             $query = "SELECT\r\n                d.Kurzname\r\n                , d.Typ\r\n                , MAX(IF ((r.Info='-') && (d.Typ = 6) ,0,r.Leistung)) \r\n                , r.Info\r\n                , MAX(IF ((r.Info='-') && (d.Typ = 6),0,r.Punkte)) AS pts    \r\n                , s.Wind\r\n                , w.Windmessung\r\n                , st.xStart\r\n                , CONCAT(DATE_FORMAT(ru.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(ru.Startzeit, '{$cfgDBtimeFormat}'))\r\n                , w.Mehrkampfreihenfolge \r\n                , ss.Bemerkung\r\n                , w.info\r\n                , ss.xSerienstart \r\n                , d.Code\r\n            FROM\r\n                start AS st USE INDEX (Anmeldung)\r\n                LEFT JOIN serienstart AS ss ON (ss.xStart = st.xStart )\r\n                LEFT JOIN resultat AS r ON (r.xSerienstart = ss.xSerienstart) \r\n                LEFT JOIN serie AS s ON (s.xSerie = ss.xSerie)\r\n                LEFT JOIN runde AS ru ON (ru.xRunde = s.xRunde)\r\n                LEFT JOIN wettkampf AS w ON (w.xWettkampf = st.xWettkampf)\r\n                LEFT JOIN disziplin_" . $_COOKIE['language'] . " AS d ON (d.xDisziplin = w.xDisziplin)\r\n            WHERE st.xAnmeldung = {$row['0']}  \r\n                {$selectionDisc} \r\n                AND ( (r.Info = '" . $cfgResultsHighOut . "' && d.Typ = 6 && r.Leistung < 0)  OR  (d.Typ = 6 && (r.Info !=  '" . $cfgResultsHighOut . "' && r.Info !=  '" . $cfgResultsHighOut1 . "' \r\n                                                 && r.Info !=  '" . $cfgResultsHighOut2 . "'  && r.Info !=  '" . $cfgResultsHighOut3 . "'  && r.Info !=  '" . $cfgResultsHighOut4 . "'\r\n                                                 && r.Info !=  '" . $cfgResultsHighOut5 . "' && r.Info !=  '" . $cfgResultsHighOut6 . "' && r.Info !=  '" . $cfgResultsHighOut7 . "' && r.Info !=  '" . $cfgResultsHighOut7 . "'))\r\n                      OR (d.Typ != 6 ) )   \r\n                \r\n               AND w.xKategorie = {$row['9']}\r\n                {$selectionMk}   \r\n                AND ru.Status = " . $cfgRoundStatus['results_done'] . "   \r\n            GROUP BY\r\n                st.xStart\r\n            ORDER BY\r\n                {$order}";
             $res = mysql_query($query);
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 $count_disc = 0;
                 $remark = '';
                 $points_disc = array();
                 while ($pt_row = mysql_fetch_row($res)) {
                     $remark = $pt_row[10];
                     $lastTime = $pt_row[8];
                     if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump]) {
                         $res2 = mysql_query("SELECT r.Info FROM \r\n\t\t\t\t\t\t\t\tresultat as r\r\n\t\t\t\t\t\t\t\tLEFT JOIN serienstart as ss USING(xSerienstart)\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tss.xStart = {$pt_row['7']}\r\n\t\t\t\t\t\t\tAND\tr.Punkte = {$pt_row['4']}");
                         $row2 = mysql_fetch_array($res2);
                         $pt_row[3] = $row2[0];
                     }
                     // set wind, if required
                     if ($pt_row[6] == 1) {
                         if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeTrack]) {
                             $wind = " / " . $pt_row[5];
                         } else {
                             if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump]) {
                                 $wind = " / " . $pt_row[3];
                             }
                         }
                     } else {
                         $wind = '';
                     }
                     // format output
                     if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeThrow] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $perf = AA_formatResultMeter($pt_row[2]);
                     } else {
                         $perf = AA_formatResultTime($pt_row[2], true);
                     }
                     // show only points for number of choosed disciplines if the diszipline is done
                     $count_disc++;
                     if ($count_disc <= $disc_nr) {
                         if ($pt_row[4] > 0 || $ukc) {
                             // any points for this event
                             if ($ukc) {
                                 $pointsUKC = AA_utils_calcPointsUKC(0, $pt_row[2], 0, $row[16], $pt_row[12], $row[14], $row[0], $pt_row[13]);
                                 $points = $points + $pointsUKC;
                                 // calculate points
                                 mysql_query("UPDATE resultat SET\r\n                                                    Punkte = {$pointsUKC}\r\n                                              WHERE\r\n                                                    xSerienstart = {$pt_row['12']}");
                                 if (mysql_errno() > 0) {
                                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                 }
                                 AA_StatusChanged(0, 0, $pt_row[12]);
                             } else {
                                 $points = $points + $pt_row[4];
                                 // calculate points
                             }
                             if ($dCode == 408) {
                                 // UBS Kids Cup
                                 switch ($pt_row[1]) {
                                     case 1:
                                     case 2:
                                         $c = 1;
                                         // track
                                         break;
                                     case 4:
                                     case 5:
                                     case 6:
                                         $c = 2;
                                         // jump and high
                                         break;
                                     case 8:
                                         $c = 3;
                                         // throw
                                         break;
                                     default:
                                         $c = 0;
                                         break;
                                 }
                                 $points_disc[$c] = $pt_row[4];
                             } else {
                                 if ($ukc) {
                                     switch ($pt_row[1]) {
                                         case 1:
                                         case 2:
                                             $c = 1;
                                             // track
                                             break;
                                         case 4:
                                         case 5:
                                         case 6:
                                             $c = 2;
                                             // jump and high
                                             break;
                                         case 8:
                                             $c = 3;
                                             // throw
                                             break;
                                         default:
                                             $c = 0;
                                             break;
                                     }
                                     $points_disc[$c] = $pointsUKC;
                                 } else {
                                     $points_disc[$row[9]] = $pt_row[4];
                                 }
                             }
                             if ($ukc) {
                                 $info = $info . $sep . $pt_row[0] . " " . "&nbsp;(" . $perf . $wind . ", {$pointsUKC})";
                             } else {
                                 $info = $info . $sep . $pt_row[0] . " " . "&nbsp;(" . $perf . $wind . ", {$pt_row['4']})";
                             }
                             $sep = ", ";
                         } elseif ($pt_row[4] == 0 && $pt_row[2] >= 0) {
                             //  athlete with 0 points
                             $info = $info . $sep . $pt_row[0] . " " . "&nbsp;(" . $perf . $wind . ", {$pt_row['4']})";
                             $sep = ", ";
                         } else {
                             $count_disc--;
                             $pointTxt = "";
                             foreach ($cfgInvalidResult as $value) {
                                 if ($value['code'] == $perf) {
                                     $pointTxt = $value['short'];
                                 }
                             }
                             $info = $info . $sep . $pt_row[0] . $pt_row[11] . "&nbsp;(" . $perf . $wind . ", {$pointTxt})";
                             $sep = ", ";
                         }
                     }
                 }
                 // END WHILE combined events
                 mysql_free_result($res);
             }
             $a = $row[0];
             $name = $row[1] . " " . $row[2];
             $year = AA_formatYearOfBirth($row[3]);
             $birthDate = $row[3];
             $sex = $row[15];
             $club = $row[5];
             $ioc = $row[6];
             $remark_arr[] = $remark;
             if ($ukc) {
                 $xKat = AA_getCatUkc($row[3], $row[15], true);
             } else {
                 $xKat = $row[9];
             }
             $points_disc_keep = $points_disc;
             $dCode_keep = $dCode;
         }
         // END WHILE athlete per category
         if (!empty($a)) {
             $points_arr[] = $points;
             $points_arr_more_disc_all[$xKat][] = $points_disc;
             $name_arr[] = $name;
             $year_arr[] = $year;
             $club_arr[] = $club;
             $info_arr[] = $info;
             $ioc_arr[] = $ioc;
             $x_arr[] = $a;
             $remark_arr[] = $remark;
             $rank_arr[] = $rank;
         }
         if (!empty($cat)) {
             $u23name = '';
             if (($comb == 410 || $comb == 400) && $catEntryLimit < 23 && $sepu23) {
                 $u23name = " (U 23)";
             }
             $list->endList();
             if ($ukc) {
                 $list->printSubTitle($catUKC . ", " . $cfgUKC_Name);
             } else {
                 $list->printSubTitle($cat . "{$u23name}, " . $combName, "", "");
             }
             $list->startList();
             $list->printHeaderLine($lastTime);
             arsort($points_arr, SORT_NUMERIC);
             // sort descending by points
             $rank = 1;
             // initialize rank
             $r = 0;
             // start value for ranking
             $p = 0;
             $k = 0;
             $no_rank = 999999;
             $max_rank = $no_rank;
             foreach ($points_arr as $key => $val) {
                 $r++;
                 if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                     // limit ranks if set (export)
                     continue;
                 }
                 if ($p != $val) {
                     // not same points as previous athlete
                     $rank = $r;
                     // next rank
                 }
                 // not set rank for invalid results
                 if (preg_match("@\\(-[1]{1}@", $info_arr[$key])) {
                     $rank = $max_rank;
                     $max_rank += 1;
                     $r--;
                 }
                 $p = $val;
                 // keep current points
                 $k = $key;
                 // keep current key
                 $rank_arr[$key] = $rank;
             }
             asort($rank_arr, SORT_NUMERIC);
             // sort descending by rank
             $rank_keep = 0;
             foreach ($rank_arr as $key => $v) {
                 $val = $points_arr[$key];
                 $rank = $v;
                 if ($rank == $rank_keep) {
                     $c = 0;
                     $keep_c = 0;
                     // first rule
                     for ($i = 1; $i <= sizeof($points_disc); $i++) {
                         if ($points_arr_more_disc_all[$xKat][$key_keep][$i] > $points_arr_more_disc_all[$xKat][$key][$i]) {
                             $keep_c++;
                         } else {
                             $c++;
                         }
                     }
                     $more = ceil(sizeof($points_disc) / 2);
                     if (sizeof($points_disc) % 2 == 0) {
                         // combined with even number discs
                         $more++;
                     }
                     if ($keep_c >= $more && $keep_c > $c) {
                         $rank_arr[$key]++;
                     } else {
                         if ($c >= $more && $c > $keep_c) {
                             $rank_arr[$key_keep]++;
                         } else {
                             // second rule
                             // check the best points of the highest points of discipline
                             $k = AA_get_AthletBestPointDisc($points_arr_more_disc_all[$xKat][$key_keep], $points_arr_more_disc_all[$xKat][$key], $key_keep, $key);
                             if ($k != 0) {
                                 $rank_arr[$k]++;
                             }
                             // if $k is 0, all points of diszipline are the same -->   athletes with same rank
                         }
                     }
                 }
                 $rank_keep = $rank;
                 $key_keep = $key;
             }
             asort($rank_arr, SORT_NUMERIC);
             // sort descending by rank
             foreach ($rank_arr as $key => $v) {
                 $val = $points_arr[$key];
                 $rank = $v;
                 if ($rank >= $no_rank) {
                     $rank = '';
                 }
                 $list->printLine($rank, $name_arr[$key], $year_arr[$key], $club_arr[$key], $val, $ioc_arr[$key]);
                 $list->printInfo($info_arr[$key]);
                 // insert points into combined top performance of entry
                 mysql_query("UPDATE anmeldung SET BestleistungMK = {$val} WHERE xAnmeldung = " . $x_arr[$key]);
             }
         }
         mysql_free_result($results);
         $list->endList();
         $list->endPage();
         // end HTML page for printing
     }
     // ET DB error all teams
 }
示例#3
0
 //check if performance from base or manually entered
 $start_row['BaseEffort'] == 'y' || $start_row['Bestleistung'] == '0' ? $manual = '' : ($manual = " manual");
 // check if this is a valid selection (age on category)
 if ($event_row[5] < $agelimit || $event_row[11] != $sex) {
     $span = "<span class='highlight_red'>";
     $span_end = "</span>";
 } else {
     $span = "";
     $span_end = "";
 }
 if ($event_row[2] == $cfgDisciplineType[$strDiscTypeTrack] || $event_row[2] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $event_row[2] == $cfgDisciplineType[$strDiscTypeRelay] || $event_row[2] == $cfgDisciplineType[$strDiscTypeDistance]) {
     $class = 'time';
     if ($event_row[2] == $cfgDisciplineType[$strDiscTypeDistance]) {
         $perf = AA_formatResultTime($start_row[1]);
     } else {
         $perf = AA_formatResultTime($start_row[1], false, true);
     }
 } else {
     $class = 'meter';
     $perf = AA_formatResultMeter($start_row[1]);
 }
 //
 // merge the disciplines for a combined event
 //
 if ($event_row[10] == $cfgEventType[$strEventTypeSingleCombined]) {
     if (!$comb_start) {
         echo "</tr>";
     }
     $comb_start = true;
     $d = 1;
     // check if one of the combined events is selected
示例#4
0
				</form>
			</tr>
			<?php 
        $sql = "SELECT xWertungstabelle_Punkte\r\n\t\t\t\t\t\t   , xWertungstabelle\r\n\t\t\t\t\t\t   , d.xDisziplin\r\n\t\t\t\t\t\t   , Geschlecht\r\n\t\t\t\t\t\t   , Leistung\r\n\t\t\t\t\t\t   , Punkte \r\n\t\t\t\t\t\t   , Typ\r\n\t\t\t\t\t  FROM wertungstabelle_punkte \r\n\t\t\t\t LEFT JOIN disziplin_" . $_COOKIE['language'] . " AS d USING(xDisziplin) \r\n\t\t\t\t\t WHERE xWertungstabelle = " . $val_scoretable . " \r\n\t\t\t\t\t   AND d.xDisziplin = " . $val_discipline . " \r\n\t\t\t\t  ORDER BY Geschlecht ASC, \r\n\t\t\t\t\t\t   Punkte DESC;";
        $result = mysql_query($sql);
        $counter = 0;
        $btn = new GUI_Button('', '');
        while ($row = mysql_fetch_assoc($result)) {
            $counter++;
            $rowclass = $counter % 2 == 0 ? 'odd' : 'even';
            if ($row['Typ'] == $cfgDisciplineType[$strDiscTypeTrack] || $row['Typ'] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row['Typ'] == $cfgDisciplineType[$strDiscTypeRelay] || $row['Typ'] == $cfgDisciplineType[$strDiscTypeDistance]) {
                $secflag = false;
                if (substr($row['Leistung'], 0, 2) >= 60) {
                    $secflag = true;
                }
                $perf = AA_formatResultTime($row['Leistung'], false, $secflag);
            } else {
                $perf = AA_formatResultMeter($row['Leistung']);
            }
            ?>
				<tr class='<?php 
            echo $rowclass;
            ?>
'>
					<form name='pt<?php 
            echo $counter;
            ?>
' action='admin_scoretables.php#item_<?php 
            echo $row[0];
            ?>
' method='post'>
                // DB error
                AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
            } else {
                $sep = "";
                while ($ath_row = mysql_fetch_row($res)) {
                    if ($disc_keep != $ath_row[7]) {
                        continue;
                    }
                    $perf = 0;
                    if ($ath_row[6] == $cfgDisciplineType[$strDiscTypeJump] || $ath_row[6] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $ath_row[6] == $cfgDisciplineType[$strDiscTypeThrow] || $ath_row[6] == $cfgDisciplineType[$strDiscTypeHigh]) {
                        $perf = AA_formatResultMeter($ath_row[5]);
                    } else {
                        if ($ath_row[6] == $cfgDisciplineType[$strDiscTypeTrack] || $ath_row[6] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                            $perf = AA_formatResultTime($ath_row[5], true, true);
                        } else {
                            $perf = AA_formatResultTime($ath_row[5], true);
                        }
                    }
                    $athletes = $athletes . $sep . $ath_row[1] . ". " . $ath_row[2] . " " . $ath_row[3] . " (" . $perf . ") ";
                    $sep = ", ";
                }
                mysql_free_result($res);
            }
            $doc->printAthletes($athletes, true);
        }
        printf("</table>\n");
        mysql_free_result($result);
    }
}
// ET DB error
$doc->endPage();
示例#6
0
                } else {
                    $sb_perf = '';
                }
                if ($best_effort != 0) {
                    $pb_perf = AA_formatResultTime($best_effort, true, true);
                } else {
                    $pb_perf = '';
                }
            } else {
                if ($season_effort != 0) {
                    $sb_perf = AA_formatResultTime($season_effort, true);
                } else {
                    $sb_perf = '';
                }
                if ($best_effort != 0) {
                    $pb_perf = AA_formatResultTime($best_effort, true);
                } else {
                    $pb_perf = '';
                }
            }
        }
        ?>
			<tr>
				<th class='dialog'><?php 
        echo $row_perf['DiszName'];
        ?>
</th>
				<td class='forms_right'><?php 
        echo $pb_perf;
        ?>
</td>
     // assemble name field
     $year = AA_formatYearOfBirth($row[4]);
     $cat = $row[5];
     if (empty($row[8])) {
         // not assigned to a team
         $club = $row[7];
         // use club name
     } else {
         $club = $row[8];
         // use team name
     }
     $ioc = $row[13];
     $mkcode = $row[23];
 }
 if ($row[11] == $cfgDisciplineType[$strDiscTypeTrack] || $row[11] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row[11] == $cfgDisciplineType[$strDiscTypeRelay] || $row[11] == $cfgDisciplineType[$strDiscTypeDistance]) {
     $perf = AA_formatResultTime($row[12]);
 } else {
     $perf = AA_formatResultMeter($row[12]);
 }
 if (!is_a($doc, "PRINT_CatDiscEntryPage") && !is_a($doc, "GUI_CatDiscEntryPage") && !is_a($doc, "PRINT_ClubCatDiscEntryPage") && !is_a($doc, "GUI_ClubCatDiscEntryPage")) {
     // 403 = UBS Kids Cup
     // 799 = ...kampf
     // show all disziplines (also if performance is 0) by UBS Kids Cup and ...kampf
     if ($perf == 0 && $row[23] != 408 && $row[23] != 799 || $row[23] > 0 && $row[23] != 408 && $row[23] != 799 && isset($cfgCombinedDef[$row[23]]) && $perf > 0) {
         //$Info = ($row[17]!="") ? ' ('.$row[17].')' : '';
         $Info = $row[18] != "" ? ' (' . $row[18] . ')' : '';
         $noFee = false;
         if ($row[18] != "" && $m != $row[19]) {
             if ($row[23] > 0 && isset($cfgCombinedDef[$row[23]])) {
                 // normal combined
                 $disc = $disc . $sep . $row[19] . $Info;
        function update()
        {
            require './lib/utils.lib.php';
            require './lib/cl_result.lib.php';
            // update result ID
            // ----------------
            if ($this->reply->getAction() == RES_ACT_INSERT || $this->reply->getAction() == RES_ACT_DELETE) {
                $item = '';
                if ($this->reply->getAction() == RES_ACT_INSERT) {
                    $item = $this->reply->getKey();
                }
                ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                echo $_POST['obj'];
                ?>
.item.value="<?php 
                echo $item;
                ?>
";
//-->
</script>
<?php 
            }
            // update page with formatted result, info
            // ---------------------------------------
            // after insert, update action
            if ($this->reply->getAction() == RES_ACT_UPDATE || $this->reply->getAction() == RES_ACT_INSERT) {
                // track disciplines, with or without wind
                if ($this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeNone']] || $this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrack']] || $this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrackNoWind']] || $this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeDistance']] || $this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeRelay']]) {
                    $perf = AA_formatResultTime($this->reply->getPerformance());
                } else {
                    $perf = AA_formatResultMeter($this->reply->getPerformance());
                }
                ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                echo $_POST['obj'];
                ?>
.perf.value="<?php 
                echo $perf;
                ?>
";
//-->
</script>
<?php 
                // technical disciplines: update wind
                if ($this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']]) {
                    ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                    echo $_POST['obj'];
                    ?>
.wind.value="<?php 
                    echo $this->reply->getInfo();
                    ?>
";
//-->
</script>
<?php 
                } else {
                    if ($this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                        ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                        echo $_POST['obj'];
                        ?>
.attempts.value="<?php 
                        echo $this->reply->getInfo();
                        ?>
";
//-->
</script>
<?php 
                    }
                }
            } else {
                if ($this->reply->getAction() == RES_ACT_DELETE) {
                    // technical disciplines: clear wind
                    if ($this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']]) {
                        ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                        echo $_POST['obj'];
                        ?>
.wind.value="";
//-->
</script>
<?php 
                    } else {
                        if ($this->type == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                            ?>
<script type="text/javascript">
<!--
	parent.frames[1].document.<?php 
                            echo $_POST['obj'];
                            ?>
.attempts.value="";
//-->
</script>
<?php 
                        }
                    }
                }
            }
            // ET insert/update, delete
        }
 function processDiscipline($event, $disctype, $catname, $discname, $windmeas, $list)
 {
     global $rFrom, $rTo, $limitRank, $date;
     require 'config.inc.php';
     $teams = array();
     // team array
     $countRes = 3;
     // results per team counting
     $order_perf = "";
     $order_perf_sort = "";
     $valid_result = "";
     if ($disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow]) {
         $order_perf = "DESC";
         $order_perf_sort = "DESC";
     } else {
         if ($disctype == $cfgDisciplineType[$strDiscTypeJump]) {
             if ($windmeas == 1) {
                 // with wind
                 $order_perf = "DESC, r.Info ASC";
                 $order_perf_sort = "DESC";
             } else {
                 // without wind
                 $order_perf = "DESC";
                 $order_perf_sort = "DESC";
             }
         } else {
             if ($disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $order_perf = "DESC";
                 $order_perf_sort = "DESC";
                 $valid_result = " AND (r.Info LIKE '%O%' OR r.Leistung < 0)";
             } else {
                 $order_perf = "ASC";
                 $order_perf_sort = "ASC";
             }
         }
     }
     $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, r.Leistung) * -1), r.Leistung)";
     $sql = "\r\n        SELECT\r\n            ts.xTeamsm\r\n            , ts.Name\r\n            , v.Name\r\n            , at.Name\r\n            , at.Vorname\r\n            , a.Startnummer\r\n            , " . $sql_leistung . " AS leistung_neu\r\n            , at.xAthlet\r\n            , r.Leistung \r\n            , ss.Rang\r\n        FROM\r\n            teamsm AS ts\r\n            LEFT JOIN verein AS v ON (v.xVerein = ts.xVerein)\r\n            LEFT JOIN teamsmathlet AS tsa ON (tsa.xTeamsm = ts.xTeamsm)\r\n            LEFT JOIN anmeldung AS a ON (a.xAnmeldung = tsa.xAnmeldung)\r\n            LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n            LEFT jOIN start AS st ON (st.xAnmeldung = tsa.xAnmeldung)\r\n            LEFT JOIN serienstart AS ss ON (ss.xStart = st.xStart )\r\n            LEFT JOIN resultat AS r ON ( r.xSerienstart = ss.xSerienstart)\r\n            LEFT JOIN serie AS se ON (ss.xSerie = se.xSerie)\r\n            LEFT JOIN runde as ru ON (se.xRunde = ru.xRunde)  \r\n        WHERE\r\n            ts.xWettkampf = {$event}       \r\n            AND st.xWettkampf = {$event}  \r\n            AND ru.Datum LIKE '" . $date . "'  \r\n            {$valid_result}    \r\n        ORDER BY\r\n            ts.xTeamsm\r\n            , leistung_neu {$order_perf}\r\n    ";
     $res = mysql_query($sql);
     if (mysql_errno() > 0) {
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $team = 0;
         // current team
         $c = 0;
         // count results
         $athletes = array();
         $teams_notValid = array();
         // team array
         while ($row = mysql_fetch_array($res)) {
             $row_res[6] = $row_res[6] == 1 || $row_res[6] == 2 || $row_res[6] == 3 || $row_res[6] == 4 ? $row_res[6] * -1 : ($row_res[6] == 9 ? -99 : $row_res[6]);
             if (isset($athletes[$row[7]])) {
                 continue;
             } else {
                 $athletes[$row[7]] = 1;
             }
             if ($team != $row[0]) {
                 if ($team > 0) {
                     $countAthl = count($teams[$team]['athletes']);
                     if ($countAthl < $countRes) {
                         $teams[$team]['perf'] = 0;
                         $teams[$team]['perfTot'] = 0;
                         $teams[$team]['rankTot'] = 0;
                         $teams[$team]['perfBest'] = 0;
                         $teams[$team]['rankBest'] = 0;
                         $teams[$team]['perfNotValid'] = 0;
                         $teams_notValid[$team]['club'] = $teams[$team]['club'];
                         $teams_notValid[$team]['name'] = $teams[$team]['name'];
                         $teams_notValid[$team]['perf'] = 0;
                         $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
                     } else {
                         $notValidPerf = false;
                         $countNotValid = 0;
                         foreach ($teams[$team]['athletes'] as $key => $val) {
                             if ($pos = strpos($val, "-1") || ($pos = strpos($val, "-2") || ($pos = strpos($val, "-3") || ($pos = strpos($val, "-4"))))) {
                                 $notValidPerf = true;
                                 $countNotValid++;
                             }
                         }
                         if (!$notValidPerf) {
                             $teams[$team]['perf'] /= $countRes;
                         } else {
                             $countValid = $countRes - $countNotValid;
                             if (isset($teams[$team]['athletes'][3])) {
                                 if ($pos = strpos($teams[$team]['athletes'][0], "-1") || ($pos = strpos($teams[$team]['athletes'][0], "-2") || ($pos = strpos($teams[$team]['athletes'][0], "-3") || ($pos = strpos($teams[$team]['athletes'][0], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][0];
                                     $teams[$team]['athletes'][0] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][0]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 } elseif ($pos = strpos($teams[$team]['athletes'][1], "-1") || ($pos = strpos($teams[$team]['athletes'][1], "-2") || ($pos = strpos($teams[$team]['athletes'][1], "-3") || ($pos = strpos($teams[$team]['athletes'][1], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][1];
                                     $teams[$team]['athletes'][1] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][1]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 } elseif ($pos = strpos($teams[$team]['athletes'][2], "-1") || ($pos = strpos($teams[$team]['athletes'][2], "-2") || ($pos = strpos($teams[$team]['athletes'][2], "-3") || ($pos = strpos($teams[$team]['athletes'][2], "-4"))))) {
                                     $tmp_at = $teams[$team]['athletes'][2];
                                     $teams[$team]['athletes'][2] = substr($teams[$team]['athletes'][3], 1, -1);
                                     list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][2]);
                                     $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                                 }
                                 if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeNone']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrack']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrackNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeDistance']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeRelay']]) {
                                     $perf = new PerformanceTime($atPerf, $secFlag);
                                     $atPerf = $perf->getPerformance();
                                 } else {
                                     if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJumpNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeThrow']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                                         $perf = new PerformanceAttempt($performance);
                                         $atPerf = $perf->getPerformance();
                                     }
                                 }
                                 if ($countNotValid == 2) {
                                     $teams[$team]['perf'] += $atPerf;
                                     $teams[$team]['perf'] = $teams[$team]['perf'] / $countNotValid;
                                 } elseif ($countNotValid == 1) {
                                     $teams[$team]['perf'] += $atPerf;
                                     $teams[$team]['perf'] = $teams[$team]['perf'] / $countRes;
                                     $notValidPerf = false;
                                 } elseif ($countNotValid == 3) {
                                     $teams[$team]['perf'] += $atPerf;
                                 }
                             }
                         }
                         if ($order_perf == 'ASC') {
                             if ($notValidPerf) {
                                 $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                                 $teams[$team]['perf'] = 99999999;
                             }
                         } else {
                             if ($notValidPerf) {
                                 $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                             }
                         }
                     }
                 }
                 $team = $row[0];
                 $teams[$team]['club'] = $row[2];
                 $teams[$team]['name'] = $row[1];
                 $c = 0;
             }
             $perf = 0;
             $perf_print = 0;
             $rank = 0;
             $asc = true;
             if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $perf = $row[6];
                 $asc = false;
                 if ($row[8] >= 0) {
                     $perf_print = AA_formatResultMeter($row[6]);
                 } else {
                     $perf_print = $perf * -1;
                 }
             } else {
                 $perf = ceil($row[6] / 10) * 10;
                 // round up 1000
                 $asc = true;
                 if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                     $perf_print = AA_formatResultTime($row[6], true, true);
                 } else {
                     $perf_print = AA_formatResultTime($row[6], true);
                 }
             }
             $rank = $row[9];
             if ($c < $countRes) {
                 $teams[$team]['perf'] += $perf;
                 $teams[$team]['perfTot'] += $perf;
                 $teams[$team]['rankTot'] += $rank;
                 if ($asc) {
                     if ($perf < $teams[$team]['perfBest'] || $teams[$team]['perfBest'] == 0) {
                         $teams[$team]['perfBest'] = $perf;
                         $teams[$team]['rankBest'] = $rank;
                     }
                 } else {
                     if ($perf > $teams[$team]['perfBest']) {
                         $teams[$team]['perfBest'] = $perf;
                         $teams[$team]['rankBest'] = $rank;
                     }
                 }
                 $teams[$team]['athletes'][] = "{$row['3']} {$row['4']}, {$perf_print}";
             } else {
                 $teams[$team]['athletes'][] = "[{$row['3']} {$row['4']}, {$perf_print}]";
             }
             $c++;
         }
         if ($team > 0) {
             // calc last team
             $countAthl = count($teams[$team]['athletes']);
             if ($countAthl < $countRes) {
                 $teams[$team]['perf'] = 0;
                 $teams[$team]['perfNotValid'] = 0;
                 $teams_notValid[$team]['club'] = $teams[$team]['club'];
                 $teams_notValid[$team]['name'] = $teams[$team]['name'];
                 $teams_notValid[$team]['perf'] = 0;
                 $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
             } else {
                 $notValidPerf = false;
                 $countNotValid = 0;
                 foreach ($teams[$team]['athletes'] as $key => $val) {
                     if ($pos = strpos($val, "-1") || ($pos = strpos($val, "-2") || ($pos = strpos($val, "-3") || ($pos = strpos($val, "-4"))))) {
                         $notValidPerf = true;
                         $countNotValid++;
                     }
                 }
                 if (!$notValidPerf) {
                     $teams[$team]['perf'] /= $countRes;
                 } else {
                     $countValid = $countRes - $countNotValid;
                     if (isset($teams[$team]['athletes'][3])) {
                         if ($pos = strpos($teams[$team]['athletes'][0], "-1") || ($pos = strpos($teams[$team]['athletes'][0], "-2") || ($pos = strpos($teams[$team]['athletes'][0], "-3") || ($pos = strpos($teams[$team]['athletes'][0], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][0];
                             $teams[$team]['athletes'][0] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][0]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         } elseif ($pos = strpos($teams[$team]['athletes'][1], "-1") || ($pos = strpos($teams[$team]['athletes'][1], "-2") || ($pos = strpos($teams[$team]['athletes'][1], "-3") || ($pos = strpos($teams[$team]['athletes'][1], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][1];
                             $teams[$team]['athletes'][1] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][1]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         } elseif ($pos = strpos($teams[$team]['athletes'][2], "-1") || ($pos = strpos($teams[$team]['athletes'][2], "-2") || ($pos = strpos($teams[$team]['athletes'][2], "-3") || ($pos = strpos($teams[$team]['athletes'][2], "-4"))))) {
                             $tmp_at = $teams[$team]['athletes'][2];
                             $teams[$team]['athletes'][2] = substr($teams[$team]['athletes'][3], 1, -1);
                             list($at, $atPerf) = split('[,]', $teams[$team]['athletes'][2]);
                             $teams[$team]['athletes'][3] = "[" . $tmp_at . "]";
                         }
                         if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeNone']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrack']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeTrackNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeDistance']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeRelay']]) {
                             $perf = new PerformanceTime($atPerf, $secFlag);
                             $atPerf = $perf->getPerformance();
                         } else {
                             if ($disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJump']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeJumpNoWind']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeThrow']] || $disctype == $GLOBALS['cfgDisciplineType'][$GLOBALS['strDiscTypeHigh']]) {
                                 $perf = new PerformanceAttempt($performance);
                                 $atPerf = $perf->getPerformance();
                             }
                         }
                         if ($countNotValid == 2) {
                             $teams[$team]['perf'] += $atPerf;
                             $teams[$team]['perf'] = $teams[$team]['perf'] / $countNotValid;
                         } elseif ($countNotValid == 1) {
                             $teams[$team]['perf'] += $atPerf;
                             $teams[$team]['perf'] = $teams[$team]['perf'] / $countRes;
                             $notValidPerf = false;
                         } elseif ($countNotValid == 3) {
                             $teams[$team]['perf'] += $atPerf;
                         }
                     }
                 }
                 if ($order_perf == 'ASC') {
                     if ($notValidPerf) {
                         $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                         $teams[$team]['perf'] = 99999999;
                     }
                 } else {
                     if ($notValidPerf) {
                         $teams[$team]['perfNotValid'] = $teams[$team]['perf'];
                     }
                 }
             }
         }
         $teams_valid = array();
         foreach ($teams as $k => $arr_team) {
             if (!isset($teams_notValid[$k]['name'])) {
                 $teams_valid[$k]['name'] = $teams[$k]['name'];
                 $teams_valid[$k]['club'] = $teams[$k]['club'];
                 $teams_valid[$k]['perf'] = $teams[$k]['perf'];
                 $teams_valid[$k]['perfTot'] = $teams[$k]['perfTot'];
                 $teams_valid[$k]['rankTot'] = $teams[$k]['rankTot'];
                 $teams_valid[$k]['perfBest'] = $teams[$k]['perfBest'];
                 $teams_valid[$k]['rankBest'] = $teams[$k]['rankBest'];
                 $teams_valid[$k]['perfNotValid'] = $teams[$k]['perfNotValid'];
                 $teams_valid[$k]['athletes'] = $teams[$k]['athletes'];
             }
         }
         $teams = $teams_valid;
         //
         // print team ranking
         //
         if (count($teams) > 0) {
             $list->printSubTitle($catname, $discname, "");
             $list->startList();
             $list->printHeaderLine();
             usort($teams, "cmp_{$order_perf_sort}");
             // sort by performance
             $teams = array_merge($teams, $teams_notValid);
             $rank = 1;
             // initialize rank
             $r = 0;
             // start value for ranking
             $p = 0;
             foreach ($teams as $team) {
                 $r++;
                 if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                     // limit ranks if set (export)
                     continue;
                 }
                 if ($team['perf'] > 0) {
                     $rank = $r;
                 } else {
                     $rank = '';
                 }
                 if ($team['perf'] == 99999999) {
                     $team['perf'] = $team['perfNotValid'];
                 }
                 $perf = 0;
                 if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                     $perf = AA_formatResultMeter($team['perf']);
                 } else {
                     if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                         $perf = AA_formatResultTime($team['perf'], true, true);
                     } else {
                         $perf = AA_formatResultTime($team['perf'], true);
                     }
                 }
                 if ($perf == 0 || !empty($team['perfNotValid'])) {
                     $rank = '';
                 }
                 $list->printLine($rank, $team['name'], $team['club'], $perf);
                 // print each athlete with result for team
                 $tmp = "";
                 foreach ($team['athletes'] as $athlete) {
                     $end = "";
                     list($name, $perfNotValid) = split(',', $athlete);
                     if (strpos($perfNotValid, "]")) {
                         $perfNotValid = substr($perfNotValid, 0, -1);
                         $end = "]";
                     }
                     if ($perfNotValid == $cfgInvalidResult['DNS']['code']) {
                         $perfNotValid = $cfgInvalidResult['DNS']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['DNF']['code']) {
                         $perfNotValid = $cfgInvalidResult['DNF']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['DSQ']['code']) {
                         $perfNotValid = $cfgInvalidResult['DSQ']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     } elseif ($perfNotValid == $cfgInvalidResult['NRS']['code']) {
                         $perfNotValid = $cfgInvalidResult['NRS']['short'];
                         $athlete = $name . ', ' . $perfNotValid . $end;
                     }
                     //$list->printInfo($athlete);
                     $tmp .= $athlete . " / ";
                 }
                 $list->printInfo(substr($tmp, 0, -2));
                 $p = $team['perf'];
                 // keep current performance
                 $keep_team = $team;
                 // keep current performance
             }
             $list->endList();
         }
     }
 }
 function AA_speaker_Track($event, $round, $layout)
 {
     require './lib/cl_gui_menulist.lib.php';
     require './lib/cl_gui_resulttable.lib.php';
     require './lib/cl_performance.lib.php';
     require './config.inc.php';
     require './lib/common.lib.php';
     $mergedMain = AA_checkMainRound($round);
     if ($mergedMain != 1) {
         $relay = AA_checkRelay($event);
         // check, if this is a relay event
         $status = AA_getRoundStatus($round);
         $svm = AA_checkSVM(0, $round);
         // decide whether to show club or team name
         // 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&show_efforts=none", $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/>";
                     }
                     // show qualification info if another round follows
                     $nextRound = AA_getNextRound($event, $round);
                     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) {
                             }
                             echo "{$strQualification}: {$row['0']} {$strQualifyTop}, {$row['1']} {$strQualifyPerformance}";
                             echo "<p/>";
                         }
                         // ET DB error
                         mysql_free_result($result);
                     }
                     // ET next round
                     // display all athletes
                     if ($relay == FALSE) {
                         // single event
                         $query = "\r\n                SELECT\r\n                    r.Bahnen\r\n                    , rt.Name\r\n                    , rt.Typ\r\n                    , s.xSerie\r\n                    , s.Bezeichnung\r\n                    , s.Wind\r\n                    , s.Film\r\n                    , s.Status\r\n                    , ss.xSerienstart\r\n                    , ss.Position\r\n                    , ss.Rang\r\n                    , ss.Qualifikation\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                    , at.Land\r\n                    , st.Bestleistung\r\n                    , at.xAthlet\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 rundentyp_" . $_COOKIE['language'] . " AS rt ON rt.xRundentyp = r.xRundentyp\r\n                    LEFT JOIN anlage AS an ON an.xAnlage = s.xAnlage\r\n                WHERE \r\n                    r.xRunde = {$round} \r\n                ORDER BY\r\n                    heatid\r\n                    , ss.Position\r\n            ";
                     } else {
                         // relay event
                         $query = "\r\n                SELECT\r\n                    r.Bahnen\r\n                    , rt.Name\r\n                    , rt.Typ\r\n                    , s.xSerie\r\n                    , s.Bezeichnung\r\n                    , s.Wind\r\n                    , s.Film\r\n                    , s.Status\r\n                    , ss.xSerienstart\r\n                    , ss.Position\r\n                    , ss.Rang\r\n                    , ss.Qualifikation\r\n                    , sf.Name\r\n                    , if('" . $svm . "', te.Name, v.Name)  \r\n                    , LPAD(s.Bezeichnung,5,'0') as heatid\r\n                    , r.xRunde\r\n                    , st.xStart\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 staffel AS sf ON (sf.xStaffel = st.xStaffel  )\r\n                    LEFT JOIN verein AS v ON (v.xVerein = sf.xVerein)\r\n                    LEFT JOIN team AS te ON(sf.xTeam = te.xTeam)\r\n                    LEFT JOIN rundentyp_" . $_COOKIE['language'] . " AS rt ON rt.xRundentyp = r.xRundentyp\r\n                    LEFT JOIN anlage AS an ON an.xAnlage = s.xAnlage\r\n                WHERE \r\n                    r.xRunde = {$round}  \r\n                ORDER BY\r\n                    heatid\r\n                    , ss.Position";
                     }
                     $result = mysql_query($query);
                     if (mysql_errno() > 0) {
                         // DB error
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         // initialize variables
                         $h = 0;
                         // heat counter
                         $p = 0;
                         // position counter (to evaluate empty heats
                         $tracks = 0;
                         $resTable = new GUI_TrackResultTable($round, $layout, $status, $nextRound);
                         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) {
                                     $resTable->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} {$row['4']}";
                                 } else {
                                     // more than one round
                                     $title = "{$row['1']}: {$row['2']}{$row['4']}";
                                 }
                                 // increment colspan to include ranking and qualification
                                 $c = 0;
                                 if ($status == $cfgRoundStatus['results_done']) {
                                     $c++;
                                     if ($nextRound > 0) {
                                         $c++;
                                     }
                                 }
                                 $resTable->printHeatTitle($row[3], $row[4], $title, $row[7], $row[6], $row[5]);
                                 if ($relay == FALSE) {
                                     // athlete display
                                     $resTable->printAthleteHeader('', $round);
                                 } else {
                                     // relay display
                                     $resTable->printRelayHeader('', $round);
                                 }
                             }
                             // 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 = $resTable->printEmptyTracks($p, $row[9] - 1, 6 + $c);
                                 }
                             }
                             // ET empty tracks
                             /*
                              * Athlete/Relay data lines
                              */
                             // get performance
                             $perf = '';
                             $perfRounded = '';
                             $res = mysql_query("\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\trs.xResultat\r\n\t\t\t\t\t\t, rs.Leistung\r\n\t\t\t\t\t\t, rs.Info\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\tresultat AS rs\r\n\t\t\t\t\tWHERE rs.xSerienstart = {$row['8']}\r\n\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\trs.Leistung ASC\r\n\t\t\t\t");
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 $resrow = mysql_fetch_row($res);
                                 if ($resrow != NULL) {
                                     // result found
                                     $perf = AA_formatResultTime($resrow[1]);
                                     $perfRounded = AA_formatResultTime($resrow[1], true);
                                 }
                                 mysql_free_result($res);
                             }
                             // ET DB error
                             // print lines
                             if ($relay == FALSE) {
                                 $resTable->printAthleteLine($row[9], $row[12], "{$row['13']} {$row['14']}", AA_formatYearOfBirth($row[15]), $row[16], AA_formatResultTime($row[19], true), $perfRounded, $row[10], $row[11], $row[18], $row[20]);
                             } else {
                                 // relay
                                 // get Athletes
                                 $arrAthletes = array();
                                 $sql = "SELECT at.Vorname, at.Name, at.Jahrgang, a.Startnummer FROM\r\n\t\t\t\t\t\t\t\tstaffelathlet as sfat\r\n\t\t\t\t\t\t\t\tLEFT JOIN start as st ON sfat.xAthletenstart = st.xStart\r\n\t\t\t\t\t\t\t\tLEFT JOIN anmeldung as a USING(xAnmeldung)\r\n\t\t\t\t\t\t\t\tLEFT JOIN athlet as at USING(xAthlet)\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tsfat.xStaffelstart = {$row['16']}\r\n\t\t\t\t\t\t\tAND\tsfat.xRunde = {$row['15']}\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\tsfat.Position";
                                 $res_at = mysql_query($sql);
                                 if (mysql_errno() > 0) {
                                     // DB error
                                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                 } else {
                                     while ($row_at = mysql_fetch_array($res_at)) {
                                         $arrAthletes[] = array($row_at[1], $row_at[0], AA_formatYearOfBirth($row_at[2]), $row_at[3]);
                                     }
                                 }
                                 $arrAthletes = count($arrAthletes) > 0 ? $arrAthletes : 0;
                                 $resTable->printRelayLine($row[9], $row[12], $row[13], $perfRounded, $row[10], $row[11], $arrAthletes);
                             }
                         }
                         // 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++;
                                 $resTable->printEmptyTracks($p, $tracks, 6 + $c);
                             }
                         }
                         // ET track disciplines
                         $resTable->endTable();
                         mysql_free_result($result);
                     }
                     // ET DB error
                 }
             }
         }
         // ET heat seeding done
     } else {
         AA_printErrorMsg($strErrMergedRoundSpeaker);
     }
 }
 function AA_sheets_processCombined($xCategory, $category, $wTyp)
 {
     require './config.inc.php';
     // get athlete info per category and team
     $sql = "\r\n        SELECT\r\n            DISTINCT(a.xAnmeldung)\r\n            , at.Name\r\n            , at.Vorname\r\n            , at.Jahrgang\r\n            , t.xTeam\r\n            , t.Name\r\n            , v.Name\r\n            , IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land  \r\n        FROM\r\n            anmeldung AS a\r\n            LEFT JOIN athlet AS at ON (at.xAthlet = a.xAthlet)\r\n            INNER JOIN team AS t ON (t.xTeam = a.xTeam   )\r\n            LEFT JOIN verein AS v ON (v.xVerein = t.xVerein)\r\n            LEFT JOIN start as st ON (st.xAnmeldung = a.xAnmeldung  )\r\n            LEFT JOIN wettkampf as w ON (w.xWettkampf = st.xWettkampf)\r\n            LEFT JOIN region AS re ON (at.xRegion = re.xRegion)    \r\n        WHERE \r\n            a.xMeeting = " . $_COOKIE['meeting_id'] . "  \r\n            AND w.xKategorie = {$xCategory}\r\n            AND w.Typ = {$wTyp}\r\n        ORDER BY\r\n            t.xTeam\r\n    ";
     $results = mysql_query($sql);
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $evaluation = 5;
         // nbr of athletes included in total result
         $a = 0;
         $club = '';
         $info = '';
         $name = '';
         $points = 0;
         $team = '';
         $sep = '';
         $tm = '';
         $year = '';
         $country = '';
         while ($row = mysql_fetch_row($results)) {
             // store previous athlete before processing new athlete
             if ($a != $row[0] && $a > 0) {
                 $athleteList[] = array("points" => $points, "name" => $name, "year" => $year, "info" => $info, "country" => $country);
                 $points = 0;
                 $info = '';
                 $sep = '';
             }
             // store previous team before processing new team
             if ($tm != $row[4] && $tm > 0) {
                 usort($athleteList, "AA_sheets_cmp");
                 // sort athletes by points
                 // nbr of athletes to include in team result
                 $total = 0;
                 for ($i = 0; $i < $evaluation; $i++) {
                     $total = $total + $athleteList[$i]['points'];
                 }
                 $teamList[] = array("points" => $total, "name" => $team, "club" => $club, "athletes" => $athleteList);
                 $team = '';
                 $club = '';
                 unset($athleteList);
                 $sep = '';
             }
             $tm = $row[4];
             // keep current team
             // events
             $sql = "\r\n                SELECT\r\n                    d.Kurzname\r\n                    , d.Typ\r\n                    , MAX(r.Leistung)\r\n                    , r.Info\r\n                    , MAX(r.Punkte) AS pts\r\n                    , s.Wind\r\n                    , w.Windmessung\r\n                FROM\r\n                    start AS st USE INDEX (Anmeldung)\r\n                    LEFT JOIN serienstart AS ss ON (ss.xStart = st.xStart)\r\n                    LEFT JOIN resultat AS r ON (r.xSerienstart = ss.xSerienstart)\r\n                    LEFT JOIN serie AS s ON (s.xSerie = ss.xSerie) \r\n                    LEFT JOIN runde AS ru ON (ru.xRunde = s.xRunde)\r\n                    LEFT JOIN wettkampf AS w  ON (w.xWettkampf = st.xWettkampf)\r\n                    LEFT JOIN disziplin_" . $_COOKIE['language'] . " AS d ON (d.xDisziplin = w.xDisziplin)\r\n                WHERE \r\n                    st.xAnmeldung = {$row['0']}                 \r\n                    AND w.Typ = " . $cfgEventType[$strEventTypeClubCombined] . "  \r\n                    AND r.Info != '" . $cfgResultsHighOut . "'\r\n                GROUP BY\r\n                    st.xStart\r\n                ORDER BY\r\n                    ru.Datum\r\n                    , ru.Startzeit\r\n            ";
             $res = mysql_query($sql);
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 while ($pt_row = mysql_fetch_row($res)) {
                     // set wind, if required
                     if ($pt_row[6] == 1) {
                         if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeTrack]) {
                             $wind = " / " . $pt_row[5];
                         } else {
                             if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump]) {
                                 $wind = " / " . $pt_row[3];
                             }
                         }
                     } else {
                         $wind = '';
                     }
                     // format output
                     if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeThrow] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $perf = AA_formatResultMeter($pt_row[2], true);
                     } else {
                         $perf = AA_formatResultTime($pt_row[2], true);
                     }
                     // calculate points
                     $points = $points + $pt_row[4];
                     // accumulate points
                     if ($pt_row[4] > 0) {
                         // any points for this event
                         $info = $info . $sep . $pt_row[0] . "&nbsp;(" . $perf . $wind . ")";
                         $sep = ", ";
                     }
                 }
                 // END WHILE combined events
                 mysql_free_result($res);
             }
             $a = $row[0];
             $name = $row[1] . " " . $row[2];
             $year = AA_formatYearOfBirth($row[3]);
             $team = $row[5];
             $club = $row[6];
             $country = $row[7];
         }
         // END WHILE athlete per category
         mysql_free_result($results);
         if (!empty($tm)) {
             // last athlete
             $athleteList[] = array("points" => $points, "name" => $name, "year" => $year, "info" => $info, "country" => $country);
             // last team
             usort($athleteList, "AA_sheets_cmp");
             // sort athletes by points
             $total = 0;
             for ($i = 0; $i < $evaluation; $i++) {
                 $total = $total + $athleteList[$i]['points'];
             }
             $teamList[] = array("points" => $total, "name" => $team, "club" => $club, "athletes" => $athleteList);
         }
         // print team sheets
         usort($teamList, "AA_sheets_cmp");
         foreach ($teamList as $team) {
             if (is_a($GLOBALS[$list], "PRINT_TeamSheet")) {
                 // page for printing
                 // page break after each team
                 if ($GLOBALS['AA_TC'] > 0) {
                     // not first team
                     $GLOBALS[$list]->insertPageBreak();
                 }
                 $GLOBALS['AA_TC']++;
                 // team counter
                 // set up list of other competitors
                 $sep = '';
                 $competitors = '';
                 foreach ($teamList as $comp) {
                     if ($comp['name'] != $team['name']) {
                         $competitors = $competitors . $sep . $comp['club'];
                         // club
                         $sep = ', ';
                     }
                 }
                 $GLOBALS[$list]->printHeader($team['club'] . " (" . $team['name'] . ")", $category, $competitors);
             } else {
                 $GLOBALS[$list]->printHeaderCombined($team['club'] . " (" . $team['name'] . ")", $category);
             }
             $i = 0;
             foreach ($team['athletes'] as $athlete) {
                 if ($i >= $evaluation) {
                     // show only athletes included in end result
                     break;
                 }
                 $i++;
                 $GLOBALS[$list]->printLineCombined($athlete['name'], $athlete['year'], $athlete['points'], $athlete['country']);
                 $GLOBALS[$list]->printDisciplinesCombined($athlete['info']);
             }
             if (is_a($GLOBALS[$list], "PRINT_TeamSheet")) {
                 // page for printing
                 $GLOBALS[$list]->printTotal($team['points']);
                 $GLOBALS[$list]->printFooter();
             } else {
                 $GLOBALS[$list]->printTotalCombined($team['points']);
             }
         }
         // FOREACH team
     }
     // ET DB error all teams
 }
示例#12
0
 function gen_result_xml_UKC_CM($file, $meeting_nr)
 {
     //function returns containing number of results in xml-file
     $nbr_effort_ukc = 0;
     global $cfgDisciplineType, $cfgEventType, $strEventTypeSingleCombined, $strEventTypeClubCombined, $strDiscTypeTrack, $strDiscTypeTrackNoWind, $strDiscTypeRelay, $strDiscTypeDistance, $cfgRoundStatus, $strDiscTypeJump, $strDiscTypeJumpNoWind, $strDiscTypeThrow, $strDiscTypeHigh, $cfgCombinedWO, $cfgCombinedDef, $cfgUKC_disc;
     $this->gzip_open($file);
     // begin xml
     $this->write_xml_open("kidDataset", array('version' => date('y-m-d')));
     $this->write_xml_open("event");
     //
     // output contest data
     //
     $indoor = '0';
     $query = "\r\n            SELECT\r\n                m.*\r\n                , s.Name as Stadion\r\n                , s.Ueber1000m\r\n                , s.Halle\r\n            FROM \r\n                meeting as m \r\n                LEFT JOIN stadion as s ON m.xStadion = s.xStadion \r\n            WHERE xMeeting = " . $_COOKIE['meeting_id'];
     $res = mysql_query($query);
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $row = mysql_fetch_assoc($res);
         mysql_free_result($res);
         if (empty($meeting_nr)) {
             $this->write_xml_finished("eventNumber", $row['Nummer']);
             // not xControl for UBS kidscup
         } else {
             $this->write_xml_finished("eventNumber", $meeting_nr);
         }
         $this->write_xml_finished("name", str_replace('&', '&amp;', $row['Name']));
         $this->write_xml_finished("eventStart", $row['DatumVon']);
         $this->write_xml_finished("eventEnd", $row['DatumBis']);
         $this->write_xml_finished("location", $row['Ort']);
         $this->write_xml_finished("stadium", $row['Stadion']);
         $this->write_xml_finished("amountSpectators", " ");
         $this->write_xml_open("athletes");
         if ($row['Ueber1000m'] == 'y') {
             $global_rankadd = "A";
         }
         if ($row['Saison'] == 'I') {
             $indoor = "1";
         }
         // 1 = indoor , 0 = outdoor
     }
     // get enrolement per athlete
     $checkyear = date('Y') - 16;
     $sql = "SELECT DISTINCT \r\n                a.xAnmeldung\r\n                , at.Name\r\n                , at.Vorname\r\n                , at.Jahrgang\r\n                \r\n                , IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)\r\n                , IF(at.xRegion = 0, at.Land, re.Anzeige)\r\n                , 0\r\n                , d.Name\r\n               \r\n                \r\n                \r\n                , ka.Alterslimite \r\n                , d.Code \r\n                , at.xAthlet\r\n                , at.Geschlecht               \r\n            FROM\r\n                anmeldung AS a\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 start as st ON (st.xAnmeldung = a.xAnmeldung ) \r\n                LEFT JOIN wettkampf as w  ON (w.xWettkampf = st.xWettkampf) \r\n                LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (w.xDisziplin = d.xDisziplin)\r\n                LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n                LEFT JOIN kategorie AS ka ON (ka.xKategorie = a.xKategorie)     \r\n                LEFT JOIN region as re ON (at.xRegion = re.xRegion) \r\n            WHERE a.xMeeting = " . $_COOKIE['meeting_id'] . "             \r\n            AND at.Jahrgang > {$checkyear} AND (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ")\r\n            AND st.anwesend = 0 \r\n            ORDER BY at.Geschlecht, at.Jahrgang,  at.Name, at.Vorname,  d.Anzeige";
     $results = mysql_query($sql);
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         while ($row = mysql_fetch_row($results)) {
             if ($roundsUkc[$row[10]] == "") {
                 $roundsUkc[$row[10]] = 0;
             }
             $roundsUkc[$row[10]]++;
         }
     }
     //
     // get all disciplines
     //
     $selection = " (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") AND ";
     $sql = "  SELECT                        \r\n                    w.Typ,\r\n                    w.Windmessung,\r\n                    d.Typ,\r\n                    d.Code,\r\n                    k.Code,\r\n                    w.xWettkampf,\r\n                    d.Kurzname,\r\n                    w.Mehrkampfcode,\r\n                    0,\r\n                    d.Staffellaeufer,  \r\n                    r.xRunde,\r\n                    w.info  \r\n                FROM \r\n                    wettkampf as w \r\n                    LEFT JOIN runde as r ON (w.xWettkampf = r.xWettkampf)  \r\n                LEFT JOIN\r\n                    disziplin_" . $_COOKIE['language'] . " as d ON d.xDisziplin = w.xDisziplin\r\n                LEFT JOIN\r\n                    kategorie as k ON k.xKategorie = w.xKategorie     \r\n                WHERE {$selection} r.xRunde > 0 AND  \r\n                   \r\n                    w.xMeeting = " . $_COOKIE['meeting_id'] . "                  \r\n                ORDER BY\r\n                    k.Code                      \r\n                    , w.info\r\n                    , w.xKategorie\r\n                    , d.Anzeige";
     // the order "k.Code, w.xKategorie" makes sense if there are multiple self made categories (without any code)
     $res = mysql_query($sql);
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $current_type = "";
         $combined = "";
         $current_cat = "";
         $current_xcat = 0;
         $GLOBALS['rounds'] = array();
         $combined = array();
         $fetched_events = array();
         while ($row = mysql_fetch_array($res)) {
             //
             // generate results for combined events
             //
             //
             // first of all, print all single results (athletes and relays)
             //
             $order_perf = "";
             $valid_result = "";
             if ($row[2] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeThrow]) {
                 $order_perf = "DESC";
             } else {
                 if ($row[2] == $cfgDisciplineType[$strDiscTypeJump]) {
                     if ($row[1] == 1) {
                         // with wind
                         $order_perf = "DESC";
                     } else {
                         // without wind
                         $order_perf = "DESC";
                     }
                 } else {
                     if ($row[2] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $order_perf = "DESC";
                         $valid_result = " AND (r.Info LIKE '%O%') ";
                     } else {
                         $order_perf = "ASC";
                     }
                 }
             }
             // check if merged rounds
             $sqlEvents = AA_getMergedEventsFromEvent($row[5]);
             if (empty($sqlEvents)) {
                 $sqlSeparate = "ru.xRunde = " . $row[10];
             } else {
                 $sqlSeparate = "ss.RundeZusammen = " . $row[10];
             }
             $checkyear = date('Y') - 16;
             $selection = " at.Jahrgang > {$checkyear} AND ";
             // by merged rounds the result must be uploded separate
             $query = "\r\n                        SELECT\r\n                            ss.xSerienstart\r\n                            , ss.Rang\r\n                            , ss.Qualifikation\r\n                            , r.Leistung\r\n                            , r.Info\r\n                            , s.Bezeichnung\r\n                            , s.Wind\r\n                            , r.Punkte\r\n                            , v.Name\r\n                            , at.Name\r\n                            , at.Vorname\r\n                            , at.Jahrgang\r\n                            , at.Land\r\n                            , at.xAthlet\r\n                            , at.Lizenznummer\r\n                            , ru.Datum\r\n                            , rt.Code as Typ\r\n                            , at.Bezahlt\r\n                            , at.Geburtstag\r\n                            , at.Geschlecht\r\n                            , v.xCode as Vereincode\r\n                            , k.Code as Katathlet\r\n                            , ru.xRunde\r\n                            , s.Handgestoppt\r\n                            , at.Lizenztyp\r\n                            , a.Vereinsinfo\r\n                            , rt.Typ\r\n                            \r\n                            , if (ss.RundeZusammen > 0,ss.RundeZusammen,ru.xRunde) as spezRound     \r\n                            , a.kidID\r\n                            , at.Adresse\r\n                            , at.Plz\r\n                            , at.Ort\r\n                            , at.Email  \r\n                            , re.Anzeige as Kanton   \r\n                            , v.Name as Vereinname\r\n                            , a.xAnmeldung\r\n                        FROM\r\n                            runde as ru\r\n                            LEFT JOIN serie AS s ON (ru.xRunde = s.xRunde)\r\n                            LEFT JOIN serienstart AS ss ON (ss.xSerie = s.xSerie)\r\n                            LEFT JOIN resultat AS r ON (r.xSerienstart = ss.xSerienstart)\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 rundentyp_" . $_COOKIE['language'] . " AS rt ON (ru.xRundentyp = rt.xRundentyp)\r\n                            LEFT JOIN kategorie AS k ON (a.xKategorie = k.xKategorie)                             \r\n                            LEFT JOIN region AS re ON (re.xRegion = at.xRegion) \r\n                        WHERE {$selection} {$sqlSeparate}\r\n                        AND ru.Status = " . $cfgRoundStatus['results_done'] . "\r\n                        AND ru.StatusUploadUKC = 0\r\n                        AND r.Leistung >= " . $GLOBALS['cfgInvalidResult']['DNS']['code'] . "\r\n                        \r\n                        {$valid_result}\r\n                        ORDER BY \r\n                            at.Jahrgang\r\n                            , at.xAthlet\r\n                            , ru.xRunde\r\n                            , r.Leistung " . $order_perf;
             $res_results = mysql_query($query);
             if (mysql_errno() > 0) {
                 echo mysql_Error();
             } else {
                 $id = 0;
                 // athletes id
                 $ru = 0;
                 // round id
                 while ($row_results = mysql_fetch_assoc($res_results)) {
                     // store round ids for later purpose
                     $GLOBALS['rounds'][] = $row_results['xRunde'];
                     //
                     // athlete results
                     //
                     if ($ru == $row_results['xRunde'] && $id == $row_results['xAthlet']) {
                         continue;
                     }
                     $ru = $row_results['xRunde'];
                     if ($id != $row_results['xAthlet']) {
                         // new athlete
                         $id = $row_results['xAthlet'];
                         if (empty($row_results['Lizenznummer']) && empty($row_results['kidID'])) {
                             $inMasterData = 1;
                             $licensePaid = 1;
                         } else {
                             $inMasterData = 0;
                             if ($row_results['Bezahlt'] == 'y') {
                                 $licensePaid = 1;
                             } else {
                                 $licensePaid = 0;
                             }
                         }
                     }
                     $perf = 0;
                     // result for alabus
                     $wind = "";
                     $perfRounded = 0;
                     // result for combined detail text
                     // add effort parameters
                     $wind = "";
                     if ($row[2] == $cfgDisciplineType[$strDiscTypeJump] || $row[2] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeThrow] || $row[2] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $perf = AA_alabusDistance($row_results['Leistung']);
                         $perfRounded = AA_formatResultMeter($row_results['Leistung']);
                         $wind = strtr($row_results['Info'], ",", ".");
                     } else {
                         $perf = AA_alabusTime($row_results['Leistung']);
                         $perfRounded = AA_formatResultTime($row_results['Leistung'], true);
                         $wind = strtr($row_results['Wind'], ",", ".");
                     }
                     if ($row[1] == 0 || $wind == "-" || $wind == "") {
                         $wind = " ";
                     }
                     if (is_numeric($row_results['Bezeichnung'])) {
                         $row_results['Bezeichnung'] = sprintf("%02s", $row_results['Bezeichnung']);
                     } else {
                         if (strlen($row_results['Bezeichnung']) == 1) {
                             $row_results['Bezeichnung'] .= "_";
                         }
                     }
                     $rank = " ";
                     $row_results['Bezeichnung'] = " ";
                     //
                     //add points for combined contests
                     if ($combined[$row_results['xAthlet']][$row[3]]['points'] < $row_results['Punkte']) {
                         $license = $row_results['Lizenznummer'];
                         if ($row_results['Lizenznummer'] == 0) {
                             $license = '';
                         }
                         $kidsID_upload = $row_results['kidID'];
                         if ($row_results['kidID'] == 0) {
                             $kidsID_upload = '';
                         }
                         if ($row[3] == 30) {
                             $perfRounded = "r" . $perfRounded;
                             // r = run
                         }
                         if ($row[3] == 331) {
                             $perfRounded = "j" . $perfRounded;
                             // j = jump
                         }
                         if ($row[3] == 386) {
                             $perfRounded = "t" . $perfRounded;
                             // t = throw
                         }
                         $combined[$row_results['xAthlet']][$row[3]] = array('wind' => $wind, 'kindOfLap' => " " . $row_results['Typ'], 'lap' => $row_results['Bezeichnung'], 'placeAddon' => $rankadd, 'indoor' => $indoor, 'points' => $row_results['Punkte'], 'effort' => $perfRounded, 'discipline' => $row[6], 'license' => $license, 'kidID' => $kidsID_upload, 'inMasterData' => $inMasterData, 'licensePaid' => $licensePaid, 'DateOfEffort' => $row_results['Datum'], 'lastName' => htmlspecialchars($row_results['Name']), 'firstName' => htmlspecialchars($row_results['Vorname']), 'birthDate' => $row_results['Jahrgang'], 'sex' => strtoupper($row_results['Geschlecht']), 'nationality' => $row_results['Land'], 'adress' => htmlspecialchars($row_results['Adresse']), 'plz' => $row_results['Plz'], 'city' => htmlspecialchars($row_results['Ort']), 'email' => $row_results['Email'], 'canton' => $row_results['Kanton'], 'accountName' => htmlspecialchars($row_results['Vereinname']), 'priority' => $combinedPriority, 'licenseType' => $row_results['Lizenztyp'], 'dCode' => $row_results['dCode'], 'xAnmeldung' => $row_results['xAnmeldung'], 'xSerienstart' => $row_results['xSerienstart'], 'Leistung' => $row_results['Leistung'], 'xathlete' => $row_results['xAthlet']);
                         // category of athlete, used for calculating the rankings
                         $combined[$row_results['xAthlet']]['catathlete'] = $row_results['Jahrgang'];
                     }
                     // check on relevant for bestlist
                     $relevant = 1;
                     if ($row_results['Typ'] == '0') {
                         // (ohne)
                         $row_results['Bezeichnung'] = '';
                     }
                     // output result data
                     if ($wind > "2" && $row[2] == $cfgDisciplineType[$strDiscTypeJump]) {
                         // since we get only the best result per xSerienstart,
                         // here we'll get the next with valid wind
                         $res_wind = mysql_query("\r\n                                        SELECT Info, Leistung FROM\r\n                                            resultat\r\n                                        WHERE\r\n                                            xSerienstart = " . $row_results['xSerienstart'] . "\r\n                                        ORDER BY\r\n                                            Leistung DESC");
                         if (mysql_errno() > 0) {
                             // DB error
                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                         } else {
                             while ($row_wind = mysql_fetch_array($res_wind)) {
                                 if ($row_wind[0] <= 2) {
                                     $perf = AA_alabusDistance($row_wind[1]);
                                     if ($perf == -98) {
                                         // -98 = Fehlversuch
                                         break;
                                     }
                                     $nbr_effort_ukc++;
                                     break;
                                 }
                             }
                         }
                     }
                     // end if wind > 2
                 }
                 // end while res_results
             }
         }
         $min_age = date('Y') - 7;
         // check on last combined event
         if (!empty($combined) && $combined_dis < 9000) {
             // combined codes 9000 and above are self made disciplines
             // calc points
             foreach ($combined as $xathlet => $disc) {
                 $points = 0;
                 $eDetails = "";
                 foreach ($disc as $xdisc => $tmp) {
                     if ($xdisc == "catathlete") {
                         continue;
                     }
                     $pointsUKC = AA_utils_calcPointsUKC(0, $tmp['Leistung'], 0, $tmp['sex'], $tmp['xSerienstart'], $xathlet, $tmp['xAnmeldung'], $xdisc);
                     $points += $pointsUKC;
                     mysql_query("UPDATE resultat SET\r\n                                                    Punkte = {$pointsUKC}\r\n                                              WHERE\r\n                                                    xSerienstart = " . $tmp['xSerienstart']);
                     if (mysql_errno() > 0) {
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     }
                     AA_StatusChanged(0, 0, $tmp['xSerienstart']);
                     if ($tmp['wind'] == " ") {
                         $tmp['wind'] = "";
                     } else {
                         if ($tmp['wind'] >= 0) {
                             $tmp['wind'] = "+" . $tmp['wind'];
                         } else {
                             $tmp['wind'] = $tmp['wind'];
                         }
                     }
                     $eDetails .= $tmp['effort'] . $tmp['wind'] . "/";
                     $birthDate = $tmp['birthDate'];
                     $sex = $tmp['sex'];
                     $tmp_xathlete = $tmp['xathlete'];
                 }
                 $eDetails = substr($eDetails, 0, -1);
                 $points = sprintf("%05d", $points);
                 $combined[$xathlet]['points'] = $points;
                 $combined[$xathlet]['edetails'] = $eDetails;
                 if ($birthDate > $min_age) {
                     $birthDate = $min_age;
                 }
                 $combined[$xathlet]['birthDate'] = $sex . $birthDate;
                 // need for sort in combination
                 $combined[$xathlet]['xathlete'] = $tmp_xathlete;
             }
             // sort for points
             array_sort($combined, '!birthDate', '!points');
             // write
             $cRank = 0;
             // rank counter
             $lp = 0;
             // remembers points of last athlete
             foreach ($combined as $xathlet => $disc) {
                 if ($roundsUkc[$disc['xathlete']] != 3) {
                     // enrolement for 3 kids cup disciplines
                     continue;
                 }
                 if ($disc['birthDate'] != $birthDate_keep) {
                     // in combination sex and birthdate
                     $cRank = 0;
                 }
                 $cRank++;
                 if ($lp != $disc['points'] || $disc['points'] == 0) {
                     $lp = $disc['points'];
                     $combined[$xathlet]['rank'] = $cRank;
                 } else {
                     // same total points
                     $c = 0;
                     $keep_c = 0;
                     for ($i = 0; $i < sizeof($cfgUKC_disc); $i++) {
                         if ($disc_keep[$cfgUKC_disc[$i]]['points'] > $disc[$cfgUKC_disc[$i]]['points']) {
                             $keep_c++;
                         } else {
                             $c++;
                         }
                     }
                     $more = ceil(sizeof($cfgUKC_disc) / 2);
                     if (sizeof($cfgUKC_disc) % 2 == 0) {
                         // combined with even number discs
                         $more++;
                     }
                     if ($keep_c >= $more && $keep_c > $c) {
                         $lp = $disc['points'];
                         $combined[$xathlet]['rank'] = $cRank;
                     } else {
                         if ($c >= $more && $c > $keep_c) {
                             $combined[$xathlet_keep]['rank'] = $cRank;
                             $combined[$xathlet]['rank'] = $cRank - 1;
                         }
                     }
                 }
                 // get information for athlete
                 $tmp = $disc;
                 $tmp['points'] = null;
                 $tmp['edetails'] = null;
                 $tmp['birthDate'] = substr($tmp['birthDate'], 1, 4);
                 $tmp['catathlete'] = null;
                 $tmp = array_values($tmp);
                 usort($tmp, array($this, "sort_perdate"));
                 $tmp = $tmp[0];
                 $run = '';
                 $jump = '';
                 $throw = '';
                 list($perf1, $perf2, $perf3) = split('[/]', $disc['edetails']);
                 if (substr($perf1, 0, 1) == 'r') {
                     $run = substr($perf1, 1);
                 } elseif (substr($perf1, 0, 1) == 'j') {
                     $jump = substr($perf1, 1);
                 } elseif (substr($perf1, 0, 1) == 't') {
                     $throw = substr($perf1, 1);
                 }
                 if (substr($perf2, 0, 1) == 'r') {
                     $run = substr($perf2, 1);
                 } elseif (substr($perf2, 0, 1) == 'j') {
                     $jump = substr($perf2, 1);
                 } elseif (substr($perf2, 0, 1) == 't') {
                     $throw = substr($perf2, 1);
                 }
                 if (substr($perf3, 0, 1) == 'r') {
                     $run = substr($perf3, 1);
                 } elseif (substr($perf3, 0, 1) == 'j') {
                     $jump = substr($perf3, 1);
                 } elseif (substr($perf3, 0, 1) == 't') {
                     $throw = substr($perf3, 1);
                 }
                 if ($run == -1 || $jump == -1 || $throw == -1) {
                     $cRank = $cRank - 1;
                     continue;
                 }
                 $xathlet_keep = $xathlet;
                 $disc_keep = $disc;
                 $birthDate_keep = $disc['birthDate'];
             }
             foreach ($combined as $xathlet => $disc) {
                 if ($roundsUkc[$disc['xathlete']] != 3) {
                     // enrolement for 3 kids cup disciplines
                     continue;
                 }
                 // get information for athlete
                 $tmp = $disc;
                 $tmp['points'] = null;
                 $tmp['edetails'] = null;
                 $tmp['birthDate'] = substr($tmp['birthDate'], 1, 4);
                 $tmp['catathlete'] = null;
                 $tmp = array_values($tmp);
                 // usort($tmp, array($this, "sort_perdate"));
                 $tmp = $tmp[0];
                 $run = '';
                 $jump = '';
                 $throw = '';
                 list($perf1, $perf2, $perf3) = split('[/]', $disc['edetails']);
                 if (substr($perf1, 0, 1) == 'r') {
                     $run = substr($perf1, 1);
                 } elseif (substr($perf1, 0, 1) == 'j') {
                     $jump = substr($perf1, 1);
                 } elseif (substr($perf1, 0, 1) == 't') {
                     $throw = substr($perf1, 1);
                 }
                 if (substr($perf2, 0, 1) == 'r') {
                     $run = substr($perf2, 1);
                 } elseif (substr($perf2, 0, 1) == 'j') {
                     $jump = substr($perf2, 1);
                 } elseif (substr($perf2, 0, 1) == 't') {
                     $throw = substr($perf2, 1);
                 }
                 if (substr($perf3, 0, 1) == 'r') {
                     $run = substr($perf3, 1);
                 } elseif (substr($perf3, 0, 1) == 'j') {
                     $jump = substr($perf3, 1);
                 } elseif (substr($perf3, 0, 1) == 't') {
                     $throw = substr($perf3, 1);
                 }
                 if ($run == -1 || $jump == -1 || $throw == -1) {
                     continue;
                 }
                 $this->write_xml_open("athlete", array('license' => $tmp['license'], 'kidID' => $tmp['kidID']));
                 $this->write_xml_open("efforts");
                 $this->write_xml_finished("run", $run);
                 $this->write_xml_finished("throw", $throw);
                 $this->write_xml_finished("jump", $jump);
                 $this->write_xml_finished("totalPoints", AA_alabusScore($disc['points']));
                 $this->write_xml_finished("position", $disc['rank']);
                 $this->write_xml_close("efforts");
                 if (empty($tmp['license']) && empty($tmp['kidID'])) {
                     $this->write_xml_open("personalData");
                     $this->write_xml_finished("lastName", $tmp['lastName']);
                     $this->write_xml_finished("firstName", $tmp['firstName']);
                     $this->write_xml_finished("ageGroup", $tmp['birthDate']);
                     $this->write_xml_finished("sex", $tmp['sex']);
                     $this->write_xml_finished("street", $tmp['adress']);
                     $this->write_xml_finished("zipCode", $tmp['plz']);
                     $this->write_xml_finished("city", $tmp['city']);
                     $this->write_xml_finished("club", $tmp['accountName']);
                     $this->write_xml_finished("email", $tmp['email']);
                     $this->write_xml_finished("canton", $tmp['canton']);
                     $this->write_xml_close("personalData");
                 }
                 $this->write_xml_close("athlete");
                 $nbr_effort_ukc++;
                 $birthDate_keep = $disc['birthDate'];
             }
         }
         $combined = array();
         // get the svm results
         mysql_free_result($res);
         $res = mysql_query("\r\n                SELECT\r\n                    w.Typ,\r\n                    w.Windmessung,\r\n                    d.Typ,\r\n                    d.Code,\r\n                    k.Code,\r\n                    w.xWettkampf,\r\n                    d.Kurzname,\r\n                    w.Mehrkampfcode,\r\n                    w.xKategorie,\r\n                    ks.Code,\r\n                    MAX(r.Datum)\r\n                FROM \r\n                    runde as r\r\n                LEFT JOIN \r\n                    wettkampf as w USING(xWettkampf) \r\n                LEFT JOIN\r\n                    disziplin_" . $_COOKIE['language'] . " as d ON d.xDisziplin = w.xDisziplin\r\n                LEFT JOIN\r\n                    kategorie as k ON k.xKategorie = w.xKategorie\r\n                LEFT JOIN\r\n                    kategorie_svm as ks ON ks.xKategorie_svm = w.xKategorie_svm\r\n                WHERE    xMeeting = " . $_COOKIE['meeting_id'] . "\r\n                GROUP BY w.xKategorie\r\n                ORDER BY\r\n                    w.xWettkampf\r\n            ");
         if (mysql_errno() > 0) {
             echo mysql_errno() . ": " . mysql_error();
         } else {
             while ($row = mysql_fetch_array($res)) {
                 //
                 // open rankinlist_team lib for calculating the svm points
                 //
                 if ($row[0] > $cfgEventType[$strEventTypeSingleCombined]) {
                     $this->write_xml_open("discipline", array('sportDiscipline' => $row[9], 'licenseCategory' => $row[4]));
                     $this->write_xml_open("teams");
                     $GLOBALS['doe'] = $row[10];
                     // date of team effort (last round date)
                     $GLOBALS['rankadd'] = $global_rankadd;
                     AA_rankinglist_Team($row[8], 'xml', "", false, $this);
                 }
             }
         }
         // close last tags
         $this->close_open_tags();
     }
     $this->gzip_close();
     return $nbr_effort_ukc;
 }
示例#13
0
 function gen_result_xml($file)
 {
     //global	$opentags;
     global $cfgDisciplineType, $cfgEventType, $strEventTypeSingleCombined, $strEventTypeClubCombined, $strDiscTypeTrack, $strDiscTypeTrackNoWind, $strDiscTypeRelay, $strDiscTypeDistance, $cfgRoundStatus, $strDiscTypeJump, $strDiscTypeJumpNoWind, $strDiscTypeThrow, $strDiscTypeHigh, $cfgCombinedWO, $cfgCombinedDef;
     $this->gzip_open($file);
     // begin xml
     $this->write_xml_open("watDataset", array('version' => date('y-m-d')));
     $this->write_xml_open("event");
     //
     // output contest data
     //
     $global_rankadd = "";
     $query = "\r\n\t\t\tSELECT\r\n\t\t\t\tm.*\r\n\t\t\t\t, s.Name as Stadion\r\n\t\t\t\t, s.Ueber1000m\r\n\t\t\t\t, s.Halle\r\n\t\t\tFROM \r\n\t\t\t\tmeeting as m LEFT JOIN stadion as s ON m.xStadion = s.xStadion \r\n\t\t\tWHERE xMeeting = " . $_COOKIE['meeting_id'];
     $res = mysql_query($query);
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $row = mysql_fetch_assoc($res);
         mysql_free_result($res);
         $this->write_xml_finished("eventNumber", $row['xControl']);
         $this->write_xml_finished("name", str_replace('&', '&amp;', $row['Name']));
         $this->write_xml_finished("eventStart", $row['DatumVon']);
         $this->write_xml_finished("eventEnd", $row['DatumBis']);
         $this->write_xml_finished("location", $row['Ort']);
         $this->write_xml_finished("stadium", $row['Stadion']);
         $this->write_xml_finished("amountSpectators", " ");
         if ($row['Ueber1000m'] == 'y') {
             $global_rankadd = "A";
         }
         //if($row['Halle'] == 'y'){ $global_rankadd .= "i"; }
         if ($row['Saison'] == 'I') {
             $global_rankadd .= "i";
         }
     }
     //
     // output all athletica generated teams (relays, svm)
     //
     $this->write_xml_open("accounts");
     $query = "\r\n\t\t\tSELECT \r\n\t\t\t\ts.xStaffel\r\n\t\t\t\t, s.Name\r\n\t\t\t\t, v.xCode as Verein\r\n\t\t\t\t, k.Code as Kat\r\n\t\t\t\t, d.Code as Dis\r\n\t\t\tFROM\r\n\t\t\t\tstaffel as s\r\n\t\t\t\t, verein as v \r\n\t\t\t\t, kategorie as k\r\n\t\t\t\t, start as st\r\n\t\t\t\t, wettkampf as w\r\n\t\t\t\t, disziplin as d\r\n\t\t\tWHERE Athleticagen = 'y'\r\n\t\t\tAND s.xVerein = v.xVerein \r\n\t\t\tAND k.xKategorie = s.xKategorie\r\n\t\t\tAND st.xStaffel = s.xStaffel\r\n\t\t\tAND w.xWettkampf = st.xWettkampf\r\n\t\t\tAND d.xDisziplin = w.xDisziplin\r\n\t\t\tAND s.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n\t\t\tORDER BY \r\n\t\t\t\tv.xVerein";
     $res_teams = mysql_query($query);
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $account = 0;
         while ($row_teams = mysql_fetch_assoc($res_teams)) {
             if (empty($row_teams['Verein']) || $row_teams['Verein'] == '999999') {
                 continue;
             }
             if ($account != $row_teams['Verein']) {
                 $this->close_open_tags("accounts");
                 $this->write_xml_open("account");
                 $this->write_xml_finished("accountCode", $row_teams['Verein']);
                 $this->write_xml_open("relays");
             }
             //$licenseCategory = ($row_teams['Kat']=='MASM' || $row_teams['Kat']=='MASW') ? '' : $row_teams['Kat'];
             $licenseCategory = $row_teams['Kat'];
             $this->write_xml_open("relay", array('id' => $row_teams['xStaffel'], 'isAthleticaGenerated' => '1'));
             $this->write_xml_finished("relayName", $row_teams['Name']);
             $this->write_xml_finished("licenseCategory", $licenseCategory);
             $this->write_xml_finished("sportDiscipline", $row_teams['Dis']);
             $this->close_open_tags("relays");
         }
     }
     $query = "\r\n\t\t\tSELECT \r\n\t\t\t\tt.xTeam\r\n\t\t\t\t, t.Name\r\n\t\t\t\t, v.xCode as Verein\r\n\t\t\t\t, k.Code as Kat\r\n\t\t\tFROM\r\n\t\t\t\tteam as t\r\n\t\t\t\t, verein as v \r\n\t\t\t\t, kategorie_svm as k\r\n\t\t\t\t, wettkampf as w\r\n\t\t\tWHERE Athleticagen = 'y'\r\n\t\t\tAND t.xVerein = v.xVerein\r\n\t\t\tAND t.xKategorie = w.xKategorie\r\n\t\t\tAND w.xKategorie_svm = k.xKategorie_svm\r\n\t\t\tAND w.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n\t\t\tGROUP BY\r\n\t\t\t\tt.xTeam\r\n\t\t\tORDER BY \r\n\t\t\t\tv.xVerein";
     $res_teams = mysql_query($query);
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $account = 0;
         while ($row_teams = mysql_fetch_assoc($res_teams)) {
             if (empty($row_teams['Verein']) || $row_teams['Verein'] == '999999') {
                 continue;
             }
             if ($account != $row_teams['Verein']) {
                 $this->close_open_tags("accounts");
                 $this->write_xml_open("account");
                 $this->write_xml_finished("accountCode", $row_teams['Verein']);
                 $this->write_xml_open("svms");
             }
             $this->write_xml_open("svm", array('id' => $row_teams['xTeam'], 'isAthleticaGenerated' => '1'));
             $this->write_xml_finished("svmName", $row_teams['Name']);
             $this->write_xml_finished("svmCategory", $row_teams['Kat']);
             $this->close_open_tags("svms");
         }
     }
     $this->close_open_tags("event");
     //
     // get all disciplines
     //
     $this->write_xml_open("disciplines");
     $res = mysql_query("\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tw.Typ,\r\n\t\t\t\t\tw.Windmessung,\r\n\t\t\t\t\td.Typ,\r\n\t\t\t\t\td.Code,\r\n\t\t\t\t\tk.Code,\r\n\t\t\t\t\tw.xWettkampf,\r\n\t\t\t\t\td.Kurzname,\r\n\t\t\t\t\tw.Mehrkampfcode,\r\n\t\t\t\t\tw.xKategorie,\r\n\t\t\t\t\td.Staffellaeufer\r\n\t\t\t\tFROM \r\n\t\t\t\t\twettkampf as w \r\n\t\t\t\t\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\tdisziplin as d ON d.xDisziplin = w.xDisziplin\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\tkategorie as k ON k.xKategorie = w.xKategorie\r\n\t\t\t\t\r\n\t\t\t\tWHERE\txMeeting = " . $_COOKIE['meeting_id'] . "\r\n\t\t\t\t\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tk.Code\r\n\t\t\t\t\t, w.xKategorie\r\n\t\t\t\t\t, w.Mehrkampfcode\r\n\t\t\t\t\t, w.Mehrkampfreihenfolge\r\n\t\t\t");
     // the order "k.Code, w.xKategorie" makes sense if there are multiple self made categories (without any code)
     if (mysql_errno() > 0) {
         echo mysql_errno() . ": " . mysql_error();
     } else {
         $current_type = "";
         $combined = "";
         $current_cat = "";
         $current_xcat = 0;
         $fetched_events = array();
         // used for combined events
         // if an athlete has no result for one discipline of a combined event,
         // the detail text has to include a 'null' result
         $GLOBALS['rounds'] = array();
         while ($row = mysql_fetch_array($res)) {
             /*if(empty($row[3]) || empty($row[4])){
             			// self made discipline or category
             			continue;
             		}*/
             if (empty($row[3])) {
                 // self made discipline
                 continue;
             }
             if (empty($row[4])) {
                 // self made category
                 $row[4] = "";
             }
             //
             // generate results for combined events
             //
             if ($current_xcat != $row[8] || $combined_dis != $row[7]) {
                 // cat or combcode changed, print combined results
                 if (!empty($combined) && $combined_dis < 9000) {
                     // combined codes 9000 and above are self made disciplines
                     $this->write_xml_open("discipline", array('sportDiscipline' => $combined_dis, 'licenseCategory' => $combined_cat));
                     $this->write_xml_open("athletes");
                     // calc points
                     foreach ($combined as $xathlet => $disc) {
                         $points = 0;
                         $eDetails = "";
                         $tmp_fe = $fetched_events;
                         // temp array for fetched events
                         foreach ($disc as $xdisc => $tmp) {
                             if ($xdisc == "catathlete") {
                                 continue;
                             }
                             // check if there are events missing for the current athlete and add 'null' entries
                             while ($tmp_fe[0][3] != $xdisc) {
                                 //$eDetails .= $tmp_fe[0][6]." (0); ";
                                 $eDetails .= "0/";
                                 array_shift($tmp_fe);
                             }
                             array_shift($tmp_fe);
                             $points += $tmp['points'];
                             if ($tmp['wind'] == " ") {
                                 $tmp['wind'] = "";
                             } else {
                                 if ($tmp['wind'] >= 0) {
                                     $tmp['wind'] = "+" . $tmp['wind'];
                                 } else {
                                     $tmp['wind'] = $tmp['wind'];
                                 }
                             }
                             //$eDetails .= $tmp['discipline']." (".$tmp['effort'].$tmp['wind']."); ";
                             $eDetails .= $tmp['discipline'] . ' ' . $tmp['effort'] . $tmp['wind'] . "/";
                         }
                         // check if last events are missing
                         while (isset($tmp_fe[0][3])) {
                             $eDetails .= "0/";
                             array_shift($tmp_fe);
                         }
                         $eDetails = substr($eDetails, 0, -1);
                         $combined[$xathlet]['points'] = $points;
                         $combined[$xathlet]['edetails'] = $eDetails;
                     }
                     // sort for points
                     usort($combined, array($this, "sort_combined"));
                     // write
                     //$rank = array();
                     //$curr_athlete_cat = "";
                     $rank = 0;
                     // athletes rank
                     $cRank = 0;
                     // rank counter
                     $lp = 0;
                     // remembers points of last athlete
                     foreach ($combined as $xathlet => $disc) {
                         $this->close_open_tags("athletes");
                         // count place for each athlete category
                         /*$curr_athlete_cat = $combined[$xathlet]['catathlete'];
                         		if(!isset($rank[$curr_athlete_cat])){
                         			$rank[$curr_athlete_cat] = 1;
                         		}else{
                         			$rank[$curr_athlete_cat]++;
                         		}*/
                         $cRank++;
                         if ($lp != $disc['points']) {
                             $rank = $cRank;
                             $lp = $disc['points'];
                         }
                         // get information for athlete, remove not needed information and sort per DateOfEffort
                         $tmp = $disc;
                         $tmp['points'] = null;
                         $tmp['edetails'] = null;
                         $tmp['catathlete'] = null;
                         $tmp = array_values($tmp);
                         usort($tmp, array($this, "sort_perdate"));
                         $tmp = $tmp[0];
                         // filter athletes not from switzerland and athletes without license
                         if ($tmp['accountCode'] == '' || $tmp['accountCode'] == '999999' || $tmp['licenseType'] == 3) {
                             continue;
                         }
                         $this->write_xml_open("athlete", array('license' => $tmp['license'], 'licensePaid' => $tmp['licensePaid'], 'licenseCat' => '', 'inMasterData' => $tmp['inMasterData']));
                         if (!$tmp['inMasterData']) {
                             $this->write_xml_finished("lastName", $tmp['lastName']);
                             $this->write_xml_finished("firstName", $tmp['firstName']);
                             $this->write_xml_finished("birthDate", $tmp['birthDate']);
                             $this->write_xml_finished("sex", $tmp['sex']);
                             $this->write_xml_finished("nationality", $tmp['nationality']);
                             $this->write_xml_finished("accountCode", $tmp['accountCode']);
                             $this->write_xml_finished("secondaccountCode", " ");
                         }
                         $this->write_xml_open("efforts");
                         $this->write_xml_open("effort");
                         $this->write_xml_finished("DateOfEffort", $tmp['DateOfEffort']);
                         $this->write_xml_finished("scoreResult", AA_alabusScore($disc['points']));
                         $this->write_xml_finished("wind", " ");
                         $this->write_xml_finished("kindOfLap", " ");
                         // round type combined (D)
                         $this->write_xml_finished("lap", " ");
                         // heat name (A_, B_, 01, 02 ..)
                         //$this->write_xml_finished("place",$rank[$curr_athlete_cat]);
                         $this->write_xml_finished("place", $rank);
                         $this->write_xml_finished("placeAddon", $tmp['placeAddon']);
                         $this->write_xml_finished("relevant", "1");
                         $this->write_xml_finished("effortDetails", $disc['edetails']);
                         $this->write_xml_close("effort");
                     }
                     $this->close_open_tags("disciplines");
                 }
                 $combined = array();
                 $fetched_events = array();
                 $combined_dis = $row[7];
                 $combined_cat = $row[4];
                 $current_cat = $row[4];
                 $current_xcat = $row[8];
             }
             // keep events rows of combined events to check on missing results after
             if ($row[0] == $cfgEventType[$strEventTypeSingleCombined]) {
                 $fetched_events[] = $row;
             }
             //
             // first of all, print all single results (athletes and relays)
             //
             $relay = AA_checkRelay($row[5]);
             // check, if this is a relay event
             $order_perf = "";
             $valid_result = "";
             $best_perf = "";
             //$highjump = false;
             if ($row[2] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeThrow]) {
                 $order_perf = "DESC";
                 $best_perf = ", max(r.Leistung) as Leistung";
             } else {
                 if ($row[2] == $cfgDisciplineType[$strDiscTypeJump]) {
                     if ($row[1] == 1) {
                         // with wind
                         //$order_perf = "DESC, r.Info ASC";
                         $order_perf = "DESC";
                     } else {
                         // without wind
                         $order_perf = "DESC";
                     }
                     $best_perf = ", max(r.Leistung) as Leistung";
                 } else {
                     if ($row[2] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $order_perf = "DESC";
                         $valid_result = " AND (r.Info LIKE '%O%') ";
                         //$highjump = true;
                         $best_perf = ", max(r.Leistung) as Leistung";
                     } else {
                         $order_perf = "ASC";
                         $best_perf = ", min(r.Leistung) as Leistung";
                     }
                 }
             }
             if ($relay == FALSE) {
                 $query = "\r\n\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\tss.xSerienstart\r\n\t\t\t\t\t\t\t, ss.Rang\r\n\t\t\t\t\t\t\t, ss.Qualifikation\r\n\t\t\t\t\t\t\t, r.Leistung\r\n\t\t\t\t\t\t\t, r.Info\r\n\t\t\t\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t\t\t\t, s.Wind\r\n\t\t\t\t\t\t\t, r.Punkte\r\n\t\t\t\t\t\t\t, v.Name\r\n\t\t\t\t\t\t\t, at.Name\r\n\t\t\t\t\t\t\t, at.Vorname\r\n\t\t\t\t\t\t\t, at.Jahrgang\r\n\t\t\t\t\t\t\t, at.Land\r\n\t\t\t\t\t\t\t, at.xAthlet\r\n\t\t\t\t\t\t\t, at.Lizenznummer\r\n\t\t\t\t\t\t\t, ru.Datum\r\n\t\t\t\t\t\t\t, rt.Code as Typ\r\n\t\t\t\t\t\t\t, at.Bezahlt\r\n\t\t\t\t\t\t\t, at.Geburtstag\r\n\t\t\t\t\t\t\t, at.Geschlecht\r\n\t\t\t\t\t\t\t, v.xCode as Vereincode\r\n\t\t\t\t\t\t\t, k.Code as Katathlet\r\n\t\t\t\t\t\t\t, ru.xRunde\r\n\t\t\t\t\t\t\t, s.Handgestoppt\r\n\t\t\t\t\t\t\t, at.Lizenztyp\r\n\t\t\t\t\t\t\t, a.Vereinsinfo\r\n                            , rt.Typ\r\n                            , ba.license_paid    \r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\trunde as ru\r\n\t\t\t\t\t\t\t, serie AS s USE INDEX (Runde)\r\n\t\t\t\t\t\t\t, serienstart AS ss\r\n\t\t\t\t\t\t\t, resultat AS r\r\n\t\t\t\t\t\t\t, start AS st\r\n\t\t\t\t\t\t\t, anmeldung AS a\r\n\t\t\t\t\t\t\t, athlet AS at\r\n\t\t\t\t\t\t\t, verein AS v\r\n\t\t\t\t\t\t\t, rundentyp AS rt\r\n\t\t\t\t\t\t\t, kategorie AS k\r\n                            LEFT JOIN base_athlete AS ba ON (ba.license = at.Lizenznummer)\r\n\t\t\t\t\t\tWHERE ru.xWettkampf = {$row['5']}\r\n\t\t\t\t\t\tAND s.xRunde = ru.xRunde\r\n\t\t\t\t\t\tAND ss.xSerie = s.xSerie\r\n\t\t\t\t\t\tAND r.xSerienstart = ss.xSerienstart\r\n\t\t\t\t\t\tAND st.xStart = ss.xStart\r\n\t\t\t\t\t\tAND a.xAnmeldung = st.xAnmeldung\r\n\t\t\t\t\t\tAND at.xAthlet = a.xAthlet\r\n\t\t\t\t\t\tAND v.xVerein = at.xVerein\r\n\t\t\t\t\t\tAND ru.xRundentyp = rt.xRundentyp\r\n\t\t\t\t\t\tAND a.xKategorie = k.xKategorie\r\n\t\t\t\t\t\tAND ru.Status = " . $cfgRoundStatus['results_done'] . "\r\n\t\t\t\t\t\tAND ru.StatusUpload = 0\r\n\t\t\t\t\t\tAND r.Leistung > 0\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t{$valid_result}\r\n\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tat.xAthlet\r\n\t\t\t\t\t\t\t, ru.xRunde\r\n\t\t\t\t\t\t\t, r.Leistung " . $order_perf;
             } else {
                 // relay event
                 $query = "\r\n\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\tss.xSerienstart\r\n\t\t\t\t\t\t\t, ss.Rang\r\n\t\t\t\t\t\t\t, ss.Qualifikation\r\n\t\t\t\t\t\t\t, r.Leistung\r\n\t\t\t\t\t\t\t, r.Info\r\n\t\t\t\t\t\t\t, s.Bezeichnung\r\n\t\t\t\t\t\t\t, s.Wind\r\n\t\t\t\t\t\t\t, r.Punkte\r\n\t\t\t\t\t\t\t, v.Name\r\n\t\t\t\t\t\t\t, sf.Name\r\n\t\t\t\t\t\t\t, sf.xStaffel\r\n\t\t\t\t\t\t\t, ru.Datum\r\n\t\t\t\t\t\t\t, rt.Code as Typ\r\n\t\t\t\t\t\t\t, st.xStart\r\n\t\t\t\t\t\t\t, ru.xRunde\r\n\t\t\t\t\t\t\t, s.Handgestoppt\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\trunde as ru\r\n\t\t\t\t\t\t\t, serie AS s USE INDEX (Runde)\r\n\t\t\t\t\t\t\t, serienstart AS ss\r\n\t\t\t\t\t\t\t, resultat AS r\r\n\t\t\t\t\t\t\t, start AS st\r\n\t\t\t\t\t\t\t, staffel AS sf\r\n\t\t\t\t\t\t\t, verein AS v\r\n\t\t\t\t\t\t\t, rundentyp as rt\r\n\t\t\t\t\t\tWHERE ru.xWettkampf = {$row['5']}\r\n\t\t\t\t\t\tAND s.xRunde = ru.xRunde\r\n\t\t\t\t\t\tAND ss.xSerie = s.xSerie\r\n\t\t\t\t\t\tAND r.xSerienstart = ss.xSerienstart\r\n\t\t\t\t\t\tAND st.xStart = ss.xStart\r\n\t\t\t\t\t\tAND sf.xStaffel = st.xStaffel\r\n\t\t\t\t\t\tAND v.xVerein = sf.xVerein\r\n\t\t\t\t\t\tAND ru.xRundentyp = rt.xRundentyp\r\n\t\t\t\t\t\tAND ru.Status = " . $cfgRoundStatus['results_done'] . "\r\n\t\t\t\t\t\tAND ru.StatusUpload = 0\r\n\t\t\t\t\t\tAND r.Leistung > 0\r\n\t\t\t\t\t\tAND v.xCode != ''\r\n\t\t\t\t\t\tAND v.xCode != '999999'\r\n\t\t\t\t\t\t{$valid_result}\r\n\t\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\t\tr.xSerienstart\r\n\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tst.xStaffel\r\n\t\t\t\t\t\t\t, ss.Rang\r\n\t\t\t\t\t\t\t " . $order_perf;
             }
             $res_results = mysql_query($query);
             if (mysql_errno() > 0) {
                 echo mysql_Error();
             } else {
                 if (mysql_num_rows($res_results) > 0) {
                     $this->write_xml_open("discipline", array('sportDiscipline' => $row[3], 'licenseCategory' => $row[4]));
                     if ($relay) {
                         $this->write_xml_open("teams");
                     } else {
                         $this->write_xml_open("athletes");
                     }
                 }
                 $id = 0;
                 // athletes id
                 $ru = 0;
                 // round id
                 while ($row_results = mysql_fetch_assoc($res_results)) {
                     // store round ids for later purpose
                     $GLOBALS['rounds'][] = $row_results['xRunde'];
                     // set "rangzusatz"
                     /*switch($row_results['Typ']){
                     			case "D":
                     			break;
                     			case "S":
                     			$rankadd = "r";
                     			break;
                     			case "V":
                     			$rankadd = "h";
                     			break;
                     			case "Z":
                     			$rankadd = "qf";
                     			break;
                     			case "X":
                     			$rankadd = "sf";
                     			break;
                     			case "Q":
                     			$rankadd = "Q";
                     			break;
                     			case "F":
                     			$rankadd = "A";
                     			break;
                     			default:
                     			$rankadd = " ";
                     		}*/
                     $season = $_SESSION['meeting_infos']['Saison'];
                     if ($saison == '') {
                         $saison = "O";
                         //if no saison is set take outdoor
                     }
                     $rankadd = " ";
                     // set "no wind" flag if not measured or wind is equal "-"
                     if ($season == 'O') {
                         // only outdoor  (indoor: never a '*' )
                         if ($row[2] == $cfgDisciplineType[$strDiscTypeJump]) {
                             if ($row[1] == 0 || $row_results['Info'] == "-" || $row_results['Info'] == "") {
                                 $rankadd .= "*";
                             }
                         }
                         if ($row[2] == $cfgDisciplineType[$strDiscTypeTrack]) {
                             if ($row[1] == 0 || $row_results['Wind'] == "-" || $row_results['Wind'] == "") {
                                 $rankadd .= "*";
                             }
                         }
                     }
                     // set "hand stopped" flag if set
                     if ($row[2] == $cfgDisciplineType[$strDiscTypeNone] || $row[2] == $cfgDisciplineType[$strDiscTypeTrack] || $row[2] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeDistance] || $row[2] == $cfgDisciplineType[$strDiscTypeRelay]) {
                         if ($row_results['Handgestoppt'] == 1) {
                             $rankadd .= "m";
                         }
                     }
                     $rankadd .= $global_rankadd;
                     if ($relay) {
                         //
                         // relay results
                         //
                         if ($id != $row_results['xStaffel']) {
                             // new relay
                             $id = $row_results['xStaffel'];
                             $this->close_open_tags("teams");
                             $this->write_xml_open("team", array('teamCode' => 'S'));
                             $this->write_xml_finished("relayId", $id);
                             // staffel id
                             $this->write_xml_open("efforts");
                         }
                         $this->write_xml_open("effort");
                         // add effort parameters
                         $this->write_xml_finished("DateOfEffort", $row_results['Datum']);
                         if ($row[2] == $cfgDisciplineType[$strDiscTypeJump] || $row[2] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeThrow] || $row[2] == $cfgDisciplineType[$strDiscTypeHigh]) {
                             $perf = AA_alabusDistance($row_results['Leistung']);
                             $this->write_xml_finished("distanceResult", $perf);
                         } else {
                             $perf = AA_alabusTime($row_results['Leistung']);
                             $this->write_xml_finished("timeResult", $perf);
                         }
                         $wind = "";
                         if ($row[1] == 1) {
                             $wind = strtr($row_results['Wind'], ",", ".");
                         } else {
                             $wind = " ";
                         }
                         if (is_numeric($row_results['Bezeichnung'])) {
                             $row_results['Bezeichnung'] = sprintf("%02s", $row_results['Bezeichnung']);
                         } else {
                             if (strlen($row_results['Bezeichnung']) == 1) {
                                 $row_results['Bezeichnung'] .= "_";
                             }
                         }
                         // check on relevant for bestlist
                         $relevant = 1;
                         if ($wind > "2") {
                             //$relevant = 0;
                         }
                         if ($row_results['Typ'] == '0') {
                             // (ohne)
                             $row_results['Bezeichnung'] = '';
                         }
                         //$this->write_xml_finished("timeResult"," ");
                         //$this->write_xml_finished("distanceResult"," ");
                         //$this->write_xml_finished("scoreResult"," ");
                         $this->write_xml_finished("wind", $wind);
                         $this->write_xml_finished("kindOfLap", " " . $row_results['Typ']);
                         // round type
                         $this->write_xml_finished("lap", $row_results['Bezeichnung']);
                         // heat name (A_, B_, 01, 02 ..)
                         $this->write_xml_finished("place", $row_results['Rang']);
                         $this->write_xml_finished("placeAddon", $rankadd);
                         $this->write_xml_finished("relevant", $relevant);
                         // get athletes for effort details
                         $cRelayAt = 4;
                         if ($row[9] > 0) {
                             // staffelläufer count of discipline
                             $cRelayAt = $row[9];
                         }
                         $query = "\r\n\t\t\t\t\t\t\t\tSELECT at.Name, at.Vorname, st.Position FROM\r\n\t\t\t\t\t\t\t\t\tstaffelathlet as st\r\n\t\t\t\t\t\t\t\t\t, start as s\r\n\t\t\t\t\t\t\t\t\t, anmeldung as a\r\n\t\t\t\t\t\t\t\t\t, athlet as at\r\n\t\t\t\t\t\t\t\tWHERE st.xStaffelstart = " . $row_results['xStart'] . "\r\n\t\t\t\t\t\t\t\tAND st.xRunde = " . $row_results['xRunde'] . "\r\n\t\t\t\t\t\t\t\tAND st.xAthletenstart = s.xStart\r\n\t\t\t\t\t\t\t\tAND s.xAnmeldung = a.xAnmeldung\r\n\t\t\t\t\t\t\t\tAND a.xAthlet = at.xAthlet\r\n\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\t\tst.Position ASC\r\n\t\t\t\t\t\t\t\tLIMIT {$cRelayAt}";
                         $res_relayat = mysql_query($query);
                         if (mysql_errno() > 0) {
                             echo mysql_error();
                         } else {
                             $eDetails = "";
                             while ($row_relayat = mysql_fetch_assoc($res_relayat)) {
                                 $eDetails .= trim($row_relayat['Name']) . " " . trim($row_relayat['Vorname']) . " / ";
                             }
                             $eDetails = substr($eDetails, 0, strlen($eDetails) - 3);
                             $this->write_xml_finished("effortDetails", $eDetails);
                         }
                         $this->write_xml_close("effort");
                     } else {
                         //
                         // athlete results
                         //
                         if ($ru == $row_results['xRunde'] && $id == $row_results['xAthlet']) {
                             continue;
                         }
                         $ru = $row_results['xRunde'];
                         // array for ordering (order after WO) combined events
                         $combinedPriority = 0;
                         /*$combinedPrio = $cfgCombinedWO[$cfgCombinedDef[$row[7]]];
                         		$combinedPriority = array_keys($combinedPrio, $row[3]);
                         		if(count($combinedPriority) > 0){
                         			$combinedPriority = $combinedPriority[0];
                         		}else{
                         			$combinedPriority = 999; // not a official discipline for this combined event
                         		}*/
                         if ($id != $row_results['xAthlet']) {
                             // new athlete
                             $id = $row_results['xAthlet'];
                             $this->close_open_tags("athletes");
                             // if athlete is not from switzerland filter him but add to combined array for correct ranking
                             // the same for athletes without license (type 3)
                             // these rules have also to be present in the parsing section of combined events (before and after result loop)
                             /*if($row_results['Vereincode'] == '' || $row_results['Vereincode'] == '999999'
                             		|| $row_results['Lizenztyp'] == 3){*/
                             if ($row_results['Lizenztyp'] == 3) {
                                 if ($row[0] == $cfgEventType[$strEventTypeSingleCombined]) {
                                     $rank = " ";
                                     $row_results['Bezeichnung'] = " ";
                                     //
                                     //add points for combined contests
                                     if ($combined[$row_results['xAthlet']][$row[3]]['points'] < $row_results['Punkte']) {
                                         $combined[$row_results['xAthlet']][$row[3]] = array('kindOfLap' => " " . $row_results['Typ'], 'lap' => $row_results['Bezeichnung'], 'placeAddon' => $rankadd, 'points' => $row_results['Punkte'], 'discipline' => $row[6], 'license' => $row_results['Lizenznummer'], 'DateOfEffort' => $row_results['Datum'], 'lastName' => $row_results['Name'], 'firstName' => $row_results['Vorname'], 'birthDate' => $birthday, 'sex' => $row_results['Geschlecht'], 'nationality' => $row_results['Land'], 'accountCode' => $row_results['Vereincode'], 'priority' => $combinedPriority, 'licenseType' => $row_results['Lizenztyp']);
                                         // category of athlete, used for calculating the rankings
                                         $combined[$row_results['xAthlet']]['catathlete'] = $row_results['Katathlet'];
                                     }
                                 }
                                 $id = 0;
                                 // if this is not set, results for the skipped athlete will be written
                                 continue;
                                 // next result/athlete
                             }
                             // license_paid = license printed (information from basa data)
                             // only upload results from athletes with license available (=license printed)
                             if ($row_results['Lizenztyp'] <= 1 && $row_results['license_paid'] == 'n') {
                                 $id = 0;
                                 // if this is not set, results for the skipped athlete will be written
                                 continue;
                                 // next result/athlete
                             }
                             if (!empty($row_results['Lizenznummer'])) {
                                 $inMasterData = 1;
                                 $licensePaid = 1;
                             } else {
                                 $inMasterData = 0;
                                 if ($row_results['Bezahlt'] == 'y') {
                                     $licensePaid = 1;
                                 } else {
                                     $licensePaid = 0;
                                 }
                             }
                             //$this->close_open_tags("athletes");
                             $this->write_xml_open("athlete", array('license' => $row_results['Lizenznummer'], 'licensePaid' => $licensePaid, 'licenseCat' => '', 'inMasterData' => $inMasterData));
                             // write athletes data if athletica generated
                             //
                             if (!$inMasterData) {
                                 if ($row_results['Land'] == "-") {
                                     $row_results['Land'] = " ";
                                 }
                                 $this->write_xml_finished("lastName", $row_results['Name']);
                                 $this->write_xml_finished("firstName", $row_results['Vorname']);
                                 $birthday = $row_results['Geburtstag'];
                                 if ($birthday == "0000-00-00") {
                                     $birthday = $row_results['Jahrgang'] . "-01-01";
                                 }
                                 $this->write_xml_finished("birthDate", $birthday);
                                 $this->write_xml_finished("sex", $row_results['Geschlecht']);
                                 $this->write_xml_finished("nationality", $row_results['Land']);
                                 $this->write_xml_finished("accountCode", $row_results['Vereincode']);
                                 $this->write_xml_finished("secondaccountCode", " ");
                             }
                             $this->write_xml_open("efforts");
                         }
                         $perf = 0;
                         // result for alabus
                         $wind = "";
                         $perfRounded = 0;
                         // result for combined detail text
                         $this->write_xml_open("effort");
                         // add effort parameters
                         $this->write_xml_finished("DateOfEffort", $row_results['Datum']);
                         $wind = "";
                         if ($row[2] == $cfgDisciplineType[$strDiscTypeJump] || $row[2] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[2] == $cfgDisciplineType[$strDiscTypeThrow] || $row[2] == $cfgDisciplineType[$strDiscTypeHigh]) {
                             $perf = AA_alabusDistance($row_results['Leistung']);
                             $perfRounded = AA_formatResultMeter($row_results['Leistung']);
                             $this->write_xml_finished("distanceResult", $perf);
                             $wind = strtr($row_results['Info'], ",", ".");
                         } else {
                             $perf = AA_alabusTime($row_results['Leistung']);
                             $perfRounded = AA_formatResultTime($row_results['Leistung'], true);
                             $this->write_xml_finished("timeResult", $perf);
                             $wind = strtr($row_results['Wind'], ",", ".");
                         }
                         if ($row[1] == 0 || $wind == "-" || $wind == "") {
                             $wind = " ";
                         }
                         if (is_numeric($row_results['Bezeichnung'])) {
                             $row_results['Bezeichnung'] = sprintf("%02s", $row_results['Bezeichnung']);
                         } else {
                             if (strlen($row_results['Bezeichnung']) == 1) {
                                 $row_results['Bezeichnung'] .= "_";
                             }
                         }
                         if ($row[0] == $cfgEventType[$strEventTypeSingleCombined]) {
                             //$rankadd = "D)".$rankadd;
                             if ($wind > 4) {
                                 // if any result has a wind of over 4 m/s, the combined result gets a flag 'w'
                                 $rankadd .= "w";
                             }
                             $rank = " ";
                             $row_results['Bezeichnung'] = " ";
                             //
                             //add points for combined contests
                             if ($combined[$row_results['xAthlet']][$row[3]]['points'] < $row_results['Punkte']) {
                                 $combined[$row_results['xAthlet']][$row[3]] = array('wind' => $wind, 'kindOfLap' => " " . $row_results['Typ'], 'lap' => $row_results['Bezeichnung'], 'placeAddon' => $rankadd, 'points' => $row_results['Punkte'], 'effort' => $perfRounded, 'discipline' => $row[6], 'license' => $row_results['Lizenznummer'], 'inMasterData' => $inMasterData, 'licensePaid' => $licensePaid, 'DateOfEffort' => $row_results['Datum'], 'lastName' => $row_results['Name'], 'firstName' => $row_results['Vorname'], 'birthDate' => $birthday, 'sex' => $row_results['Geschlecht'], 'nationality' => $row_results['Land'], 'accountCode' => $row_results['Vereincode'], 'priority' => $combinedPriority, 'licenseType' => $row_results['Lizenztyp']);
                                 // category of athlete, used for calculating the rankings
                                 $combined[$row_results['xAthlet']]['catathlete'] = $row_results['Katathlet'];
                             }
                         } else {
                             $rank = $row_results['Rang'];
                         }
                         // check on relevant for bestlist
                         $relevant = 1;
                         if ($row_results['Typ'] == '0') {
                             // (ohne)
                             $row_results['Bezeichnung'] = '';
                         }
                         // output result data
                         $this->write_xml_finished("wind", $wind);
                         $this->write_xml_finished("kindOfLap", " " . $row_results['Typ']);
                         // round type
                         $this->write_xml_finished("lap", $row_results['Bezeichnung']);
                         // heat name (A_, B_, 01, 02 ..)
                         $this->write_xml_finished("place", $rank);
                         $this->write_xml_finished("placeAddon", $rankadd);
                         $this->write_xml_finished("relevant", $relevant);
                         $this->write_xml_finished("effortDetails", " ");
                         $this->write_xml_finished("accountinfo", " " . $row_results['Vereinsinfo']);
                         $this->write_xml_finished("homologate", "1");
                         // not yet implemented -> TODO
                         $this->write_xml_close("effort");
                         if ($wind > "2" && $row[2] == $cfgDisciplineType[$strDiscTypeJump]) {
                             // since we get only the best result per xSerienstart,
                             // here we'll get the next with valid wind
                             $res_wind = mysql_query("\r\n\t\t\t\t\t\t\t\t\t\tSELECT Info, Leistung FROM\r\n\t\t\t\t\t\t\t\t\t\t\tresultat\r\n\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\t\txSerienstart = " . $row_results['xSerienstart'] . "\r\n\t\t\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\t\t\t\tLeistung DESC");
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 while ($row_wind = mysql_fetch_array($res_wind)) {
                                     if ($row_wind[0] <= 2) {
                                         $perf = AA_alabusDistance($row_wind[1]);
                                         if ($perf == -98) {
                                             // -98 = Fehlversuch
                                             break;
                                         }
                                         $this->write_xml_open("effort");
                                         $this->write_xml_finished("DateOfEffort", $row_results['Datum']);
                                         $this->write_xml_finished("distanceResult", $perf);
                                         $wind = strtr($row_wind[0], ",", ".");
                                         if ($wind == "-") {
                                             $wind = " ";
                                         }
                                         $this->write_xml_finished("wind", $wind);
                                         $this->write_xml_finished("kindOfLap", " " . $row_results['Typ']);
                                         // round type
                                         $this->write_xml_finished("lap", $row_results['Bezeichnung']);
                                         // heat name (A_, B_, 01, 02 ..)
                                         $this->write_xml_finished("place", " ");
                                         $this->write_xml_finished("placeAddon", $rankadd);
                                         $this->write_xml_finished("relevant", $relevant);
                                         $this->write_xml_finished("effortDetails", " ");
                                         $this->write_xml_close("effort");
                                         break;
                                     }
                                 }
                             }
                         }
                         // end if wind > 2
                     }
                     // end if relay or athlete
                 }
                 // end while res_results
             }
             $this->close_open_tags("disciplines");
         }
         // check on last combined event
         if (!empty($combined) && $combined_dis < 9000) {
             // combined codes 9000 and above are self made disciplines
             $this->write_xml_open("discipline", array('sportDiscipline' => $combined_dis, 'licenseCategory' => $combined_cat));
             $this->write_xml_open("athletes");
             // calc points
             foreach ($combined as $xathlet => $disc) {
                 $points = 0;
                 $eDetails = "";
                 $tmp_fe = $fetched_events;
                 foreach ($disc as $xdisc => $tmp) {
                     if ($xdisc == "catathlete") {
                         continue;
                     }
                     // check if there are events missing for the current athlete and add 'null' entries
                     while ($tmp_fe[0][3] != $xdisc) {
                         //$eDetails .= $tmp_fe[0][6]." (0); ";
                         $eDetails .= "0/";
                         array_shift($tmp_fe);
                     }
                     array_shift($tmp_fe);
                     $points += $tmp['points'];
                     if ($tmp['wind'] == " ") {
                         $tmp['wind'] = "";
                     } else {
                         //$tmp['wind'] = " / ".$tmp['wind'];
                         if ($tmp['wind'] >= 0) {
                             $tmp['wind'] = "+" . $tmp['wind'];
                         } else {
                             $tmp['wind'] = $tmp['wind'];
                         }
                     }
                     //$eDetails .= $tmp['discipline']." (".$tmp['effort'].$tmp['wind']."); ";
                     $eDetails .= $tmp['effort'] . $tmp['wind'] . "/";
                 }
                 // check if last events are missing
                 while (isset($tmp_fe[0][3])) {
                     $eDetails .= "0/";
                     array_shift($tmp_fe);
                 }
                 $eDetails = substr($eDetails, 0, -1);
                 $combined[$xathlet]['points'] = $points;
                 $combined[$xathlet]['edetails'] = $eDetails;
             }
             // sort for points
             usort($combined, array($this, "sort_combined"));
             // write
             //$rank = array();
             //$curr_athlete_cat = "";
             $rank = 0;
             // athletes rank
             $cRank = 0;
             // rank counter
             $lp = 0;
             // remembers points of last athlete
             foreach ($combined as $xathlet => $disc) {
                 $this->close_open_tags("athletes");
                 // count place for each athlete category
                 /*$curr_athlete_cat = $combined[$xathlet]['catathlete'];
                 		if(!isset($rank[$curr_athlete_cat])){
                 			$rank[$curr_athlete_cat] = 1;
                 		}else{
                 			$rank[$curr_athlete_cat]++;
                 		}*/
                 $cRank++;
                 if ($lp != $disc['points']) {
                     $rank = $cRank;
                     $lp = $disc['points'];
                 }
                 // get information for athlete
                 $tmp = $disc;
                 $tmp['points'] = null;
                 $tmp['edetails'] = null;
                 $tmp['catathlete'] = null;
                 $tmp = array_values($tmp);
                 usort($tmp, array($this, "sort_perdate"));
                 $tmp = $tmp[0];
                 // filter athletes not from switzerland and athletes without license
                 if ($tmp['accountCode'] == '' || $tmp['accountCode'] == '999999' || $tmp['licenseType'] == 3) {
                     continue;
                 }
                 $this->write_xml_open("athlete", array('license' => $tmp['license'], 'licensePaid' => $tmp['licensePaid'], 'licenseCat' => '', 'inMasterData' => $tmp['inMasterData']));
                 if (!$tmp['inMasterData']) {
                     $this->write_xml_finished("lastName", $tmp['lastName']);
                     $this->write_xml_finished("firstName", $tmp['firstName']);
                     $this->write_xml_finished("birthDate", $tmp['birthDate']);
                     $this->write_xml_finished("sex", $tmp['sex']);
                     $this->write_xml_finished("nationality", $tmp['nationality']);
                     $this->write_xml_finished("accountCode", $tmp['accountCode']);
                     $this->write_xml_finished("secondaccountCode", " ");
                 }
                 $this->write_xml_open("efforts");
                 $this->write_xml_open("effort");
                 $this->write_xml_finished("DateOfEffort", $tmp['DateOfEffort']);
                 $this->write_xml_finished("scoreResult", AA_alabusScore($disc['points']));
                 $this->write_xml_finished("wind", " ");
                 $this->write_xml_finished("kindOfLap", " ");
                 // round type combined (D)
                 $this->write_xml_finished("lap", " ");
                 // heat name (A_, B_, 01, 02 ..)
                 //$this->write_xml_finished("place",$rank[$curr_athlete_cat]);
                 $this->write_xml_finished("place", $rank);
                 $this->write_xml_finished("placeAddon", $tmp['placeAddon']);
                 $this->write_xml_finished("relevant", "1");
                 $this->write_xml_finished("effortDetails", $disc['edetails']);
                 $this->write_xml_close("effort");
             }
             $this->close_open_tags("disciplines");
         }
         $combined = array();
         // get the svm results
         mysql_free_result($res);
         $res = mysql_query("\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tw.Typ,\r\n\t\t\t\t\tw.Windmessung,\r\n\t\t\t\t\td.Typ,\r\n\t\t\t\t\td.Code,\r\n\t\t\t\t\tk.Code,\r\n\t\t\t\t\tw.xWettkampf,\r\n\t\t\t\t\td.Kurzname,\r\n\t\t\t\t\tw.Mehrkampfcode,\r\n\t\t\t\t\tw.xKategorie,\r\n\t\t\t\t\tks.Code,\r\n\t\t\t\t\tMAX(r.Datum)\r\n\t\t\t\tFROM \r\n\t\t\t\t\trunde as r\r\n\t\t\t\tLEFT JOIN \r\n\t\t\t\t\twettkampf as w USING(xWettkampf) \r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\tdisziplin as d ON d.xDisziplin = w.xDisziplin\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\tkategorie as k ON k.xKategorie = w.xKategorie\r\n\t\t\t\tLEFT JOIN\r\n\t\t\t\t\tkategorie_svm as ks ON ks.xKategorie_svm = w.xKategorie_svm\r\n\t\t\t\tWHERE\txMeeting = " . $_COOKIE['meeting_id'] . "\r\n\t\t\t\tGROUP BY w.xKategorie\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tw.xWettkampf\r\n\t\t\t");
         if (mysql_errno() > 0) {
             echo mysql_errno() . ": " . mysql_error();
         } else {
             while ($row = mysql_fetch_array($res)) {
                 //
                 // open rankinlist_team lib for calculating the svm points
                 //
                 if ($row[0] > $cfgEventType[$strEventTypeSingleCombined]) {
                     $this->write_xml_open("discipline", array('sportDiscipline' => $row[9], 'licenseCategory' => $row[4]));
                     $this->write_xml_open("teams");
                     $GLOBALS['doe'] = $row[10];
                     // date of team effort (last round date)
                     $GLOBALS['rankadd'] = $global_rankadd;
                     AA_rankinglist_Team($row[8], 'xml', "", false, $this);
                     $this->close_open_tags("disciplines");
                 }
             }
         }
         // close last tags
         $this->close_open_tags();
     }
     $this->gzip_close();
 }
 function AA_rankinglist_Combined($category, $formaction, $break, $cover, $sepu23, $cover_timing = false, $date = '%', $disc_nr, $catFrom, $catTo)
 {
     require './lib/cl_gui_page.lib.php';
     require './lib/cl_print_page.lib.php';
     require './lib/cl_export_page.lib.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     if (AA_connectToDB() == FALSE) {
         // invalid DB connection
         return;
         // abort
     }
     if (AA_checkMeetingID() == FALSE) {
         // no meeting selected
         return;
         // abort
     }
     $contestcat = " ";
     if (!empty($category)) {
         // show every category
         $contestcat = " AND w.xKategorie = {$category}";
     }
     if ($catFrom > 0) {
         $getSortCat = AA_getSortCat($catFrom, $catTo);
         if ($getSortCat[0]) {
             if ($catTo > 0) {
                 $contestcat = " AND k.Anzeige >=" . $getSortCat[$catFrom] . " AND k.Anzeige <=" . $getSortCat[$catTo] . " ";
             } else {
                 $contestcat = " AND k.Anzeige =" . $getSortCat[$catFrom] . " ";
             }
         }
     }
     $dCode = 0;
     // get athlete info per contest category
     $results = mysql_query("\r\n\tSELECT DISTINCT \r\n\t\ta.xAnmeldung\r\n\t\t, at.Name\r\n\t\t, at.Vorname\r\n\t\t, at.Jahrgang\r\n\t\t, k.Name\r\n\t\t, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)\r\n\t\t, IF(at.xRegion = 0, at.Land, re.Anzeige)\r\n\t\t, w.Mehrkampfcode\r\n\t\t, d.Name\r\n\t\t, w.xKategorie\r\n\t\t, ka.Code\r\n\t\t, ka.Name\r\n\t\t, ka.Alterslimite \r\n        , d.Code             \r\n\tFROM\r\n\t\tanmeldung AS a\r\n\t\t, athlet AS at\r\n\t\t, verein AS v\r\n\t\t, kategorie AS k\r\n\t\t, kategorie AS ka\r\n\t\t, start as st\r\n\t\t, wettkampf as w\r\n\t\t, disziplin as d\r\n\t\tLEFT JOIN region as re ON at.xRegion = re.xRegion\r\n\tWHERE a.xMeeting = " . $_COOKIE['meeting_id'] . "\r\n\t" . $contestcat . "\r\n\tAND at.xAthlet = a.xAthlet\r\n\tAND v.xVerein = at.xVerein\r\n\tAND k.xKategorie = w.xKategorie\r\n\tAND st.xAnmeldung = a.xAnmeldung\r\n\tAND w.xWettkampf = st.xWettkampf  \r\n\tAND w.Mehrkampfcode = d.Code  \r\n\tAND w.Mehrkampfcode > 0\r\n\tAND ka.xKategorie = a.xKategorie \r\n    AND st.anwesend = 0 \t\r\n\tORDER BY    \t \r\n\t\tk.Anzeige\r\n\t\t, w.Mehrkampfcode\r\n\t\t, ka.Alterslimite DESC\r\n");
     /*        
        $results= mysql_query("SELECT  
             a.xAnmeldung
             , at.Name
             , at.Vorname
             , at.Jahrgang
             , k.Name
             , IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)
             , IF(at.xRegion = 0, at.Land, re.Anzeige)
             , w.Mehrkampfcode
             , d.Name
             , w.xKategorie
             , ka.Code
             , ka.Name
             , ka.Alterslimite
         FROM
             anmeldung AS a
             LEFT JOIN athlet AS at USING (xAthlet) 
             LEFT JOIN verein AS v USING (xVerein)
             LEFT JOIN kategorie AS k ON (w.xKategorie = k.xKategorie)
             LEFT JOIN kategorie AS ka ON (ka.xKategorie = a.xKategorie) 
             LEFT JOIN start as st  ON (st.xAnmeldung = a.xAnmeldung)
             LEFT JOIN wettkampf as w On (w.xWettkampf = st.xWettkampf)
             LEFT JOIN disziplin as d ON (w.Mehrkampfcode = d.Code) 
             LEFT JOIN region as re ON at.xRegion = re.xRegion
         WHERE a.xMeeting = " . $_COOKIE['meeting_id'] ." 
          " . $contestcat . "   
         AND w.Mehrkampfcode > 0 
         GROUP BY
             a.xAnmeldung
         ORDER BY
             w.xKategorie
             , w.Mehrkampfcode
             , ka.Alterslimite DESC
             ");     
     */
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $cat = '';
         $catEntry = '';
         $catEntryLimit = "";
         $u23name = "";
         $comb = 0;
         // hold combined type
         $combName = "";
         $lastTime = "";
         // hold start time of last event for print list
         $a = 0;
         $info = '';
         $points = 0;
         $sep = '';
         $rFrom = 0;
         $rTo = 0;
         $limitRank = false;
         if ($_GET['limitRank'] == "yes" && substr($formaction, 0, 6) == "export") {
             // check if ranks are limited
             if (!empty($_GET['limitRankFrom']) && !empty($_GET['limitRankTo'])) {
                 $limitRank = true;
                 $rFrom = $_GET['limitRankFrom'];
                 $rTo = $_GET['limitRankTo'];
             }
         }
         // start a new HTML display page
         if ($formaction == 'view') {
             // display page for speaker
             $list = new GUI_CombinedRankingList($_COOKIE['meeting']);
             $list->printPageTitle("{$strRankingLists} " . $_COOKIE['meeting']);
         } elseif ($formaction == "print") {
             $list = new PRINT_CombinedRankingList($_COOKIE['meeting']);
             if ($cover == true) {
                 // print cover page
                 $list->printCover($GLOBALS['strResults'], $cover_timing);
             }
         } elseif ($formaction == "exportpress") {
             $list = new EXPORT_CombinedRankingListPress($_COOKIE['meeting'], 'txt');
         } elseif ($formaction == "exportdiplom") {
             $list = new EXPORT_CombinedRankingListDiplom($_COOKIE['meeting'], 'csv');
         }
         while ($row = mysql_fetch_row($results)) {
             $dCode = $row[13];
             // store previous before processing new athlete
             if ($a != $row[0] && $a > 0) {
                 $points_arr[] = $points;
                 if ($dCode_keep == 403) {
                     // Athletic Cup
                     $points_arr_max_disc[$xKat][] = $points_disc;
                 } else {
                     $points_arr_max_disc[$xKat][] = AA_get_MaxPointDisc($points_disc);
                 }
                 $points_arr_more_disc[$xKat][] = AA_get_MoreBestPointDisc($points_disc);
                 $points_arr_more_disc_all[$row[9]][] = $points_disc;
                 $name_arr[] = $name;
                 $year_arr[] = $year;
                 $club_arr[] = $club;
                 $info_arr[] = $info;
                 $ioc_arr[] = $ioc;
                 $x_arr[] = $a;
                 $rank_arr[] = $rank;
                 $info = '';
                 $points = 0;
                 $sep = '';
             }
             // print previous before processing new category
             if (!empty($cat) && ($row[4] != $cat || $row[7] != $comb || ($comb == 410 || $comb == 400) && $catEntry != $row[10] && $row[12] < 23 && !$bU23 && $sepu23)) {
                 $bU23 = false;
                 // set the separate flag! else it will be separated by each category
                 if (($comb == 410 || $comb == 400) && $catEntry != $row[10] && $row[12] < 23) {
                     $bU23 = true;
                 }
                 $u23name = '';
                 // set the addition for the title if this is the separated cat
                 if (($comb == 410 || $comb == 400) && $catEntryLimit < 23 && $sepu23) {
                     $u23name = " (U 23)";
                 }
                 $list->endList();
                 $list->printSubTitle($cat . "{$u23name}, " . $combName, "", "");
                 $list->startList();
                 $list->printHeaderLine($lastTime);
                 arsort($points_arr, SORT_NUMERIC);
                 // sort descending by points
                 $rank = 1;
                 // initialize rank
                 $r = 0;
                 // start value for ranking
                 $p = 0;
                 $no_rank = 999999;
                 $max_rank = $no_rank;
                 foreach ($points_arr as $key => $val) {
                     $r++;
                     if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                         // limit ranks if set (export)
                         continue;
                     }
                     if ($p != $val) {
                         // not same points as previous team
                         $rank = $r;
                         // next rank
                     }
                     // not set rank for invalid results
                     if (preg_match("@\\(-[1]{1}@", $info_arr[$key])) {
                         $rank = $max_rank;
                         $max_rank += 1;
                         $r--;
                     }
                     $rank_arr[$key] = $rank;
                     $p = $val;
                     // keep current points
                 }
                 asort($rank_arr, SORT_NUMERIC);
                 // sort descending by rank
                 $rank_keep = 0;
                 foreach ($rank_arr as $key => $v) {
                     $val = $points_arr[$key];
                     $rank = $v;
                     if ($rank == $rank_keep) {
                         if ($dCode_keep == 403) {
                             // Athletic Cup
                             $c = 0;
                             $c_max_disc1 = 0;
                             $c_max_disc2 = 0;
                             for ($i = 0; $i < 3; $i++) {
                                 if ($points_arr_max_disc[$xKat][$key_keep][$i] > $points_arr_max_disc[$xKat][$key][$i]) {
                                     $c_max_disc1++;
                                 }
                                 if ($points_arr_max_disc[$xKat][$key_keep][$i] < $points_arr_max_disc[$xKat][$key][$i]) {
                                     $c_max_disc2++;
                                 }
                             }
                             if ($c_max_disc1 == 2 && $c_max_disc2 == 1) {
                                 // two disciplines more points
                                 $rank_arr[$key]++;
                             } elseif ($c_max_disc1 == 1 && $c_max_disc2 == 2) {
                                 // two disciplines more points
                                 $rank_arr[$key_keep]++;
                             } elseif ($c_max_disc1 == 1 && $c_max_disc2 == 1) {
                                 // one discipline same points and total same points
                                 $k = AA_get_BestPointDisc($points_arr_max_disc[$xKat][$key_keep], $points_arr_max_disc[$xKat][$key], $key_keep, $key);
                                 $rank_arr[$k]++;
                             }
                         } else {
                             // other combined events
                             if ($points_arr_more_disc[$xKat][$key_keep] < $points_arr_more_disc[$xKat][$key]) {
                                 $rank_arr[$key_keep]++;
                             } elseif ($points_arr_more_disc[$xKat][$key_keep] > $points_arr_more_disc[$xKat][$key]) {
                                 $rank_arr[$key]++;
                             } else {
                                 // always same points --> check
                                 $max_key = AA_get_BestPointDisc($points_arr_more_disc_all[$xKat][$key_keep], $points_arr_more_disc_all[$xKat][$key], $key_keep, $key);
                                 $rank_arr[$max_key]++;
                             }
                         }
                     }
                     $rank_keep = $rank;
                     $key_keep = $key;
                 }
                 asort($rank_arr, SORT_NUMERIC);
                 // sort descending by rank
                 foreach ($rank_arr as $key => $v) {
                     $val = $points_arr[$key];
                     $rank = $v;
                     if ($rank >= $no_rank) {
                         $rank = '';
                     }
                     $list->printLine($rank, $name_arr[$key], $year_arr[$key], $club_arr[$key], $val, $ioc_arr[$key]);
                     $list->printInfo($info_arr[$key]);
                     // insert points into combined top performance of entry
                     mysql_query("UPDATE anmeldung SET BestleistungMK = {$val} WHERE xAnmeldung = " . $x_arr[$key]);
                 }
                 unset($points_arr);
                 unset($name_arr);
                 unset($year_arr);
                 unset($club_arr);
                 unset($info_arr);
                 unset($ioc_arr);
                 unset($x_arr);
                 unset($rank_arr);
                 if (is_a($list, "PRINT_CombinedRankingList") && $break == 'category') {
                     // page break after category
                     $list->insertPageBreak();
                 }
             }
             $cat = $row[4];
             // keep current category
             $xKat = $row[9];
             $catEntry = $row[10];
             $catEntryLimit = $row[12];
             $comb = $row[7];
             $combName = $row[8];
             // events
             $res = mysql_query("\r\n            SELECT\r\n                d.Kurzname\r\n                , d.Typ\r\n              , MAX(IF ((r.Info='-') && (d.Typ = 6) ,0,r.Leistung)) \r\n                , r.Info\r\n                , MAX(IF ((r.Info='-') && (d.Typ = 6),0,r.Punkte)) AS pts    \r\n                , s.Wind\r\n                , w.Windmessung\r\n                , st.xStart\r\n                , CONCAT(DATE_FORMAT(ru.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(ru.Startzeit, '{$cfgDBtimeFormat}'))\r\n                , w.Mehrkampfreihenfolge \r\n                , ss.Bemerkung\r\n                , w.info\r\n            FROM\r\n                start AS st USE INDEX (Anmeldung)\r\n                , serienstart AS ss \r\n                , resultat AS r \r\n                , serie AS s \r\n                , runde AS ru \r\n                , wettkampf AS w\r\n                , disziplin AS d \r\n            WHERE st.xAnmeldung = {$row['0']}\r\n            AND ss.xStart = st.xStart\r\n            AND r.xSerienstart = ss.xSerienstart\r\n            AND s.xSerie = ss.xSerie\r\n            AND ru.xRunde = s.xRunde\r\n            AND w.xWettkampf = st.xWettkampf\r\n            AND d.xDisziplin = w.xDisziplin\r\n            AND ( (r.Info = '" . $cfgResultsHighOut . "' && d.Typ = 6 && r.Leistung < 0)  OR  (r.Info !=  '" . $cfgResultsHighOut . "') )                                                                                \r\n            AND w.xKategorie = {$row['9']}\r\n            AND w.Mehrkampfcode = {$row['7']}\r\n            GROUP BY\r\n                st.xStart\r\n            ORDER BY\r\n                w.Mehrkampfreihenfolge ASC\r\n                , ru.Datum\r\n                , ru.Startzeit\r\n        ");
             /*  
             		$res = mysql_query("
             			SELECT
             				d.Kurzname
             				, d.Typ
             				, MAX(r.Leistung)
             				, r.Info
             				, MAX(r.Punkte) AS pts
             				, s.Wind
             				, w.Windmessung
             				, st.xStart
             				, CONCAT(DATE_FORMAT(ru.Datum,'$cfgDBdateFormat'), ' ', TIME_FORMAT(ru.Startzeit, '$cfgDBtimeFormat'))
             			FROM
             				start as st USE INDEX (Anmeldung)
             				, wettkampf as w
             				, runde as ru
             				, disziplin as d
             				LEFT JOIN serie AS s ON s.xRunde = ru.xRunde
             				LEFT JOIN serienstart AS ss ON ss.xSerie = s.xSerie AND ss.xStart = st.xStart
             				LEFT JOIN resultat AS r ON (r.xSerienstart = ss.xSerienstart AND r.Info != '" . $cfgResultsHighOut . "')
             				
             			WHERE st.xAnmeldung = $row[0]
             			AND w.xKategorie = $row[9]
             			AND w.Mehrkampfcode = $row[7]   
             			AND w.xWettkampf = st.xWettkampf   
                   AND d.xDisziplin = w.xDisziplin  
             			AND ru.xWettkampf = w.xWettkampf
             			AND ru.Datum LIKE '".$date."'
             			GROUP BY
             				st.xStart
             			ORDER BY
             				w.Mehrkampfreihenfolge ASC
             				, ru.Datum
             				, ru.Startzeit
             		");   
             */
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 $count_disc = 0;
                 $remark = '';
                 $points_disc = array();
                 while ($pt_row = mysql_fetch_row($res)) {
                     $remark = $pt_row[10];
                     $lastTime = $pt_row[8];
                     if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump]) {
                         $res2 = mysql_query("SELECT r.Info FROM \r\n\t\t\t\t\t\t\t\tresultat as r\r\n\t\t\t\t\t\t\t\tLEFT JOIN serienstart as ss USING(xSerienstart)\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tss.xStart = {$pt_row['7']}\r\n\t\t\t\t\t\t\tAND\tr.Punkte = {$pt_row['4']}");
                         $row2 = mysql_fetch_array($res2);
                         $pt_row[3] = $row2[0];
                     }
                     // set wind, if required
                     if ($pt_row[6] == 1) {
                         if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeTrack]) {
                             $wind = " / " . $pt_row[5];
                         } else {
                             if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump]) {
                                 $wind = " / " . $pt_row[3];
                             }
                         }
                     } else {
                         $wind = '';
                     }
                     // format output
                     if ($pt_row[1] == $cfgDisciplineType[$strDiscTypeJump] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeThrow] || $pt_row[1] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $perf = AA_formatResultMeter($pt_row[2]);
                     } else {
                         $perf = AA_formatResultTime($pt_row[2], true);
                     }
                     // show only points for number of choosed disciplines if the diszipline is done
                     $count_disc++;
                     if ($count_disc <= $disc_nr) {
                         if (!empty($pt_row[11])) {
                             $pt_row[11] = " ({$pt_row['11']})";
                         }
                         if ($pt_row[4] > 0) {
                             // any points for this event
                             $points = $points + $pt_row[4];
                             // calculate points
                             if ($dCode == 403) {
                                 // Athletic Cup
                                 switch ($pt_row[1]) {
                                     case 1:
                                     case 2:
                                         $c = 0;
                                         // track
                                         break;
                                     case 4:
                                     case 6:
                                         $c = 1;
                                         // jump and high
                                         break;
                                     case 8:
                                         $c = 2;
                                         // throw
                                         break;
                                     default:
                                         $c = 0;
                                         break;
                                 }
                                 $points_disc[$c] = $pt_row[4];
                             } else {
                                 $points_disc[$pt_row[9]] = $pt_row[4];
                             }
                             $info = $info . $sep . $pt_row[0] . $pt_row[11] . "&nbsp;(" . $perf . $wind . ", {$pt_row['4']})";
                             $sep = ", ";
                         } elseif ($pt_row[4] == 0 && $pt_row[2] >= 0) {
                             //  athlete with 0 points
                             $info = $info . $sep . $pt_row[0] . $pt_row[11] . "&nbsp;(" . $perf . $wind . ", {$pt_row['4']})";
                             $sep = ", ";
                         } else {
                             $count_disc--;
                             $pointTxt = "";
                             foreach ($cfgInvalidResult as $value) {
                                 if ($value['code'] == $perf) {
                                     $pointTxt = $value['short'];
                                 }
                             }
                             $info = $info . $sep . $pt_row[0] . $pt_row[11] . "&nbsp;(" . $perf . $wind . ", {$pointTxt})";
                             $sep = ", ";
                         }
                     }
                 }
                 // END WHILE combined events
                 mysql_free_result($res);
             }
             $a = $row[0];
             $name = $row[1] . " " . $row[2];
             $year = AA_formatYearOfBirth($row[3]);
             $club = $row[5];
             $ioc = $row[6];
             $remark_arr[] = $remark;
             $xKat = $row[9];
             $points_disc_keep = $points_disc;
             $dCode_keep = $dCode;
         }
         // END WHILE athlete per category
         if (!empty($a)) {
             $points_arr[] = $points;
             if ($dCode == 403) {
                 $points_arr_max_disc[$xKat][] = $points_disc;
             } else {
                 $points_arr_max_disc[$xKat][] = AA_get_MaxPointDisc($points_disc);
             }
             $points_arr_more_disc[$xKat][] = AA_get_MoreBestPointDisc($points_disc);
             $points_arr_more_disc_all[$xKat][] = $points_disc;
             $name_arr[] = $name;
             $year_arr[] = $year;
             $club_arr[] = $club;
             $info_arr[] = $info;
             $ioc_arr[] = $ioc;
             $x_arr[] = $a;
             $remark_arr[] = $remark;
             $rank_arr[] = $rank;
         }
         if (!empty($cat)) {
             $u23name = '';
             if (($comb == 410 || $comb == 400) && $catEntryLimit < 23 && $sepu23) {
                 $u23name = " (U 23)";
             }
             $list->endList();
             $list->printSubTitle($cat . "{$u23name}, " . $combName, "", "");
             $list->startList();
             $list->printHeaderLine($lastTime);
             arsort($points_arr, SORT_NUMERIC);
             // sort descending by points
             $rank = 1;
             // initialize rank
             $r = 0;
             // start value for ranking
             $p = 0;
             $k = 0;
             $no_rank = 999999;
             $max_rank = $no_rank;
             foreach ($points_arr as $key => $val) {
                 $r++;
                 if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                     // limit ranks if set (export)
                     continue;
                 }
                 if ($p != $val) {
                     // not same points as previous athlete
                     $rank = $r;
                     // next rank
                 } else {
                     if ($dCode == 403) {
                         // Athletic Cup
                         if ($points_arr_max_disc[$xkat][$key] > $points_arr_max_disc[$xKat][$k]) {
                             $rank_arr[$k] = $r;
                         }
                     }
                 }
                 // not set rank for invalid results
                 if (preg_match("@\\(-[1]{1}@", $info_arr[$key])) {
                     $rank = $max_rank;
                     $max_rank += 1;
                     $r--;
                 }
                 $p = $val;
                 // keep current points
                 $k = $key;
                 // keep current key
                 $rank_arr[$key] = $rank;
             }
             asort($rank_arr, SORT_NUMERIC);
             // sort descending by rank
             $rank_keep = 0;
             foreach ($rank_arr as $key => $v) {
                 $val = $points_arr[$key];
                 $rank = $v;
                 if ($rank == $rank_keep) {
                     if ($dCode == 403) {
                         // Athletic Cup
                         $c = 0;
                         $c_max_disc1 = 0;
                         $c_max_disc2 = 0;
                         for ($i = 0; $i < 3; $i++) {
                             if ($points_arr_max_disc[$xKat][$key_keep][$i] > $points_arr_max_disc[$xKat][$key][$i]) {
                                 $c_max_disc1++;
                             }
                             if ($points_arr_max_disc[$xKat][$key_keep][$i] < $points_arr_max_disc[$xKat][$key][$i]) {
                                 $c_max_disc2++;
                             }
                         }
                         if ($c_max_disc1 == 2 && $c_max_disc2 == 1) {
                             // two disciplines more points
                             $rank_arr[$key]++;
                         } elseif ($c_max_disc1 == 1 && $c_max_disc2 == 2) {
                             // two disciplines more points
                             $rank_arr[$key_keep]++;
                         } elseif ($c_max_disc1 == 1 && $c_max_disc2 == 1) {
                             // one discipline same points and total same points
                             $k = AA_get_BestPointDisc($points_arr_max_disc[$xKat][$key_keep], $points_arr_max_disc[$xKat][$key], $key_keep, $key);
                             $rank_arr[$k]++;
                         }
                     } else {
                         // other combined events
                         if ($points_arr_more_disc[$xKat][$key_keep] < $points_arr_more_disc[$xKat][$key]) {
                             $rank_arr[$key_keep]++;
                         } elseif ($points_arr_more_disc[$xKat][$key_keep] > $points_arr_more_disc[$xKat][$key]) {
                             $rank_arr[$key]++;
                         } else {
                             // always same points --> check
                             $max_key = AA_get_BestPointDisc($points_arr_more_disc_all[$xKat][$key_keep], $points_arr_more_disc_all[$xKat][$key], $key_keep, $key);
                             $rank_arr[$max_key]++;
                         }
                     }
                 }
                 $rank_keep = $rank;
                 $key_keep = $key;
             }
             asort($rank_arr, SORT_NUMERIC);
             // sort descending by rank
             foreach ($rank_arr as $key => $v) {
                 $val = $points_arr[$key];
                 $rank = $v;
                 if ($rank >= $no_rank) {
                     $rank = '';
                 }
                 $list->printLine($rank, $name_arr[$key], $year_arr[$key], $club_arr[$key], $val, $ioc_arr[$key]);
                 $list->printInfo($info_arr[$key]);
                 // insert points into combined top performance of entry
                 mysql_query("UPDATE anmeldung SET BestleistungMK = {$val} WHERE xAnmeldung = " . $x_arr[$key]);
             }
         }
         mysql_free_result($results);
         $list->endList();
         $list->endPage();
         // end HTML page for printing
     }
     // ET DB error all teams
 }
 function AA_rankinglist_Single($category, $event, $round, $formaction, $break, $cover, $biglist = false, $cover_timing = false, $date = '%', $show_efforts = 'none', $heatSeparate, $catFrom, $catTo, $discFrom, $discTo, $heatFrom, $heatTo, $athleteCat, $content_navi)
 {
     require './lib/cl_gui_page.lib.php';
     require './lib/common.lib.php';
     require './config.inc.php';
     require './config.inc.end.php';
     if (AA_connectToDB() == FALSE) {
         // invalid DB connection
         return;
         // abort
     }
     if (AA_checkMeetingID() == FALSE) {
         // no meeting selected
         return;
         // abort
     }
     $p = "./tmp";
     $fp = @fopen($p . "/live" . $round . ".html", 'w');
     if (!$fp) {
         AA_printErrorMsg($GLOBALS['strErrFileOpenFailed']);
         return;
     }
     // set up ranking list selection
     $selection = '';
     $eventMerged = false;
     $catMerged = false;
     $flagSubtitle = false;
     $flagInfoLine1 = false;
     $flagInfoLine2 = false;
     $selectionHeats = '';
     $orderAthleteCat = '';
     $saison = $_SESSION['meeting_infos']['Saison'];
     if ($saison == '') {
         $saison = "O";
         //if no saison is set take outdoor
     }
     if ($round > 0) {
         // show a specific round
         $eventMerged = false;
         $sqlEvents = AA_getMergedEventsFromEvent($event);
         if ($sqlEvents != '') {
             $selection = "w.xWettkampf IN " . $sqlEvents . " AND ";
             $eventMerged = true;
         } else {
             $selection = "w.xWettkampf =" . $event . " AND ";
         }
     } else {
         if ($category == 0) {
             // show all disciplines for every category
             $catMerged = true;
         } else {
             if ($event == 0) {
                 // show all disciplines for a specific category
                 $catMerged = false;
                 $mergedCat = AA_mergedCat($category);
                 if ($mergedCat != '') {
                     $selection = "w.xKategorie =" . $category . " AND ";
                     $catMerged = true;
                 } else {
                     $selection = "w.xKategorie =" . $category . " AND ";
                 }
             } else {
                 if ($round == 0) {
                     // show all rounds for a specific event
                     $eventMerged = false;
                     $sqlEvents = AA_getMergedEventsFromEvent($event);
                     if ($sqlEvents != '') {
                         $selection = "w.xWettkampf IN " . $sqlEvents . " AND ";
                         $eventMerged = true;
                     } else {
                         $selection = "w.xWettkampf =" . $event . " AND ";
                     }
                 }
             }
         }
     }
     if ($catFrom > 0) {
         //
         $getSortCat = AA_getSortCat($catFrom, $catTo);
         if ($getSortCat[0]) {
             if ($catTo > 0) {
                 $selection = "k.Anzeige >=" . $getSortCat[$catFrom] . " AND k.Anzeige <=" . $getSortCat[$catTo] . " AND ";
             } else {
                 $selection = "k.Anzeige =" . $getSortCat[$catFrom] . " AND ";
             }
         }
     }
     if ($discFrom > 0) {
         //
         $getSortDisc = AA_getSortDisc($discFrom, $discTo);
         if ($getSortDisc[0]) {
             if ($discTo > 0) {
                 $selection .= "d.Anzeige >=" . $getSortDisc[$discFrom] . " AND d.Anzeige <=" . $getSortDisc[$discTo] . " AND ";
             } else {
                 $selection .= "d.Anzeige =" . $getSortDisc[$discFrom] . " AND ";
             }
         }
     }
     if ($heatFrom > 0) {
         $selectionHeats = ' AND s.xSerie >= ' . $heatFrom . ' AND s.xSerie <= ' . $heatTo . ' ';
     }
     if ($athleteCat) {
         $orderAthleteCat = ' k1.Anzeige, ';
     }
     if ($catMerged & !$heatSeparate || $eventMerged & !$heatSeparate) {
         // get event rounds from DB
         $results = mysql_query("\r\n\tSELECT \r\n\t\tr.xRunde\r\n\t\t, k.Name\r\n\t\t, d.Name\r\n\t\t, d.Typ\r\n\t\t, w.xWettkampf\r\n\t\t, r.QualifikationSieger\r\n\t\t, r.QualifikationLeistung\r\n\t\t, w.Punkteformel\r\n\t\t, w.Windmessung\r\n\t\t, r.Speakerstatus\r\n\t\t, d.Staffellaeufer\r\n\t\t, CONCAT(DATE_FORMAT(r.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(r.Startzeit, '{$cfgDBtimeFormat}'))\r\n\t\t, w.xDisziplin  \r\n\tFROM\r\n\t\tathletica.wettkampf AS w\r\n\t\tLEFT JOIN athletica.kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n  \t\tLEFT JOIN athletica.disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n  \t\tLEFT JOIN athletica.runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n\tWHERE " . $selection . "\r\n\tw.xMeeting = " . $_COOKIE['meeting_id'] . " \t\r\n\tAND  (r.Status = " . $cfgRoundStatus['results_done'] . " OR r.Status = " . $cfgRoundStatus['results_in_progress'] . ") \r\n\tAND r.Datum LIKE '" . $date . "'\r\n\tORDER BY\r\n\t\tk.Anzeige\r\n\t\t, d.Anzeige\r\n\t\t, r.Datum\r\n\t\t, r.Startzeit\r\n");
     } else {
         // heats separate
         $results = mysql_query("\r\n            SELECT DISTINCT \r\n                r.xRunde , \r\n                k.Name , \r\n                d.Name , \r\n                d.Typ , \r\n                w.xWettkampf , \r\n                r.QualifikationSieger , \r\n                r.QualifikationLeistung , \r\n                w.Punkteformel , \r\n                w.Windmessung , \r\n                r.Speakerstatus , \r\n                d.Staffellaeufer , \r\n                CONCAT(DATE_FORMAT(r.Datum,'%d.%m.%y'), \r\n                ' ', \r\n                TIME_FORMAT(r.Startzeit, '%H:%i')) ,\r\n                w.xDisziplin ,  \r\n                rs.Hauptrunde     \r\n            FROM \r\n                athletica.wettkampf AS w \r\n                LEFT JOIN athletica.kategorie AS k ON (k.xKategorie = w.xKategorie) \r\n                LEFT JOIN athletica.disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                LEFT JOIN athletica.runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n                LEFT JOIN athletica.rundenset as rs ON (r.xRunde=rs.xRunde )           \r\n            WHERE \r\n                " . $selection . "  \r\n                w.xMeeting  = " . $_COOKIE['meeting_id'] . " \r\n                AND  (r.Status = " . $cfgRoundStatus['results_done'] . " OR r.Status = " . $cfgRoundStatus['results_in_progress'] . ")  \r\n                AND r.Datum LIKE '%' \r\n            ORDER BY\r\n                k.Anzeige\r\n                , d.Anzeige\r\n                , r.Datum\r\n                , r.Startzeit\r\n   ");
     }
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $limitRankSQL = "";
         $limitRank = false;
         if ($_GET['limitRank'] == "yes") {
             // check if ranks are limited, but limitRankSQL will set only if export is pressed
             if (!empty($_GET['limitRankFrom']) && !empty($_GET['limitRankTo'])) {
                 $limitRank = true;
             }
         }
         // get url
         $url = '';
         $result = mysql_query("\r\n            SELECT\r\n                url\r\n            FROM\r\n                athletica_liveResultate.config");
         if (mysql_errno() > 0) {
             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
         } else {
             $row = mysql_fetch_row($result);
             $url = $row[0];
         }
         // start a new HTML display page
         if ($formaction == 'view' || $formaction == 'speaker') {
             // display page
             $list = new GUI_RankingList($_COOKIE['meeting']);
             $list->content = $cfgHtmlStart1;
             if (empty($GLOBALS['cfgDir'])) {
                 $list->content .= "<meta http-equiv='refresh' content='" . $GLOBALS['cfgMonitorReload'] . "; url=http://" . $url . "/live" . $round . ".html'>";
             } else {
                 $list->content .= "<meta http-equiv='refresh' content='" . $GLOBALS['cfgMonitorReload'] . "; url=http://" . $url . "/" . $GLOBALS['cfgDir'] . "/live" . $round . ".html'>";
             }
             $list->content .= $cfgHtmlStart2;
             $list->content .= $content_navi;
             $list->content .= "</div ><div id='content_pc'><div id='content_pda'>";
             $list->printPageTitle("{$strRankingLists} " . $_COOKIE['meeting']);
         } elseif ($formaction == "print") {
             $list = new PRINT_RankingList($_COOKIE['meeting']);
             if ($cover == true) {
                 // print cover page
                 $list->printCover($GLOBALS['strResults'], $cover_timing);
             }
         } elseif ($formaction == "exportpress") {
             $list = new EXPORT_RankingListPress($_COOKIE['meeting'], 'txt');
             if ($limitRank) {
                 $limitRankSQL = " AND ss.Rang <= " . $_GET['limitRankTo'] . " AND ss.Rang >= " . $_GET['limitRankFrom'] . " ";
             }
         } elseif ($formaction == "exportdiplom") {
             $list = new EXPORT_RankingListDiplom($_COOKIE['meeting'], 'csv');
             if ($limitRank) {
                 $limitRankSQL = " AND ss.Rang <= " . $_GET['limitRankTo'] . " AND ss.Rang >= " . $_GET['limitRankFrom'] . " ";
             }
         }
         // initialize variables
         $cat = '';
         $evnt = 0;
         while ($row = mysql_fetch_row($results)) {
             // for a combined event, the rounds are merged, so jump until the next event
             if ($cRounds > 1) {
                 $cRounds--;
                 continue;
             }
             $roundSQL = "s.xRunde = {$row['0']}";
             $cRounds = 0;
             // check page  break
             if (is_a($list, "PRINT_RankingList") && $cat != '' && ($break == 'discipline' || $break == 'category' && $row[1] != $cat)) {
                 $list->insertPageBreak();
             }
             if ($row[3] == $cfgDisciplineType[$strDiscTypeTrackTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeRelay]) {
                 $eval = $cfgEvalType[$strEvalTypeHeat];
             } else {
                 $eval = $cfgEvalType[$strEvalTypeAll];
             }
             $roundName = '';
             $type = '';
             $res = mysql_query("\r\n\t\t\tSELECT\r\n                rt.Name\r\n                , rt.Typ\r\n                , rt.Wertung\r\n            FROM\r\n                athletica.runde\r\n                LEFT JOIN athletica.rundentyp_" . $_COOKIE['language'] . " AS rt ON (rt.xRundentyp = runde.xRundentyp)\r\n            WHERE \r\n                runde.xRunde = {$row['0']}             \r\n\t\t");
             if (mysql_errno() > 0) {
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 if (mysql_num_rows($res) > 0) {
                     $row_rt = mysql_fetch_row($res);
                     if ($row_rt[1] == '0') {
                         $type = " ";
                         $row_rt[0] = '';
                     } else {
                         $type = $row_rt[0] . " ";
                     }
                     $eval = $row_rt[2];
                     if ($round != 0) {
                         // specific round selected
                         $roundName = $row_rt[0];
                     }
                 }
                 mysql_free_result($res);
             }
             if ($evnt != $row[4]) {
                 // if this is a combined event, dont fragment list by rounds
                 $combined = AA_checkCombined($row[4]);
                 // not selectet a specific round
                 if ($round == 0 && $combined) {
                     $res_c = mysql_query("SELECT \r\n\t\t\t\t\t\t\t\tr.xRunde\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\tathletica.wettkampf as w\r\n\t\t\t\t\t\t\t\t LEFT JOIN athletica.runde as r ON (r.xWettkampf = w.xWettkampf)\r\n\t\t\t\t\t\t\tWHERE\tw.xWettkampf = " . $row[4]);
                     if (mysql_errno() > 0) {
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         $cRounds = mysql_num_rows($res_c);
                         $roundSQL = "s.xRunde IN (";
                         while ($row_c = mysql_Fetch_array($res_c)) {
                             $roundSQL .= $row_c[0] . ",";
                         }
                         $roundSQL = substr($roundSQL, 0, -1) . ")";
                     }
                 }
                 // set up category and discipline title information
                 $flagSubtitle = true;
                 // set flag to print the subtitle later
                 if ($formaction == 'speaker' && AA_getNextRound($row[4], $row[0]) == 0) {
                     // last round: show ceremony status
                     $list->printCeremonyStatus($row[0], $row[9]);
                 }
                 // print qualification mode if round selected
                 $info = '';
                 if ($round > 0 && ($row[5] > 0 || $row[6] > 0)) {
                     //$info = $GLOBALS['strQualification'] .": "
                     //			. $row[5] . " &nbsp;" . $GLOBALS['$strQualifyTop'] .", "
                     //			. $row[6] . " &nbsp;" . $GLOBALS['strQualifyPerformance'];
                     $info = "{$strQualification}: " . $row[5] . " {$strQualifyTop}, " . $row[6] . " {$strQualifyPerformance}";
                     $flagInfoLine1 = true;
                     // set flag to print later the qualification mode if round selected
                     $info_save1 = $info;
                     //$list->printInfoLine($info);
                     $qual_mode = TRUE;
                 }
                 // print qualification descriptions if required
                 $info = '';
                 if ($row[5] > 0 || $row[6] > 0) {
                     //foreach($GLOBALS['cfgQualificationType'] as $qt)
                     foreach ($cfgQualificationType as $qt) {
                         $info = $info . $qt['token'] . " =" . $qt['text'] . "&nbsp;&nbsp;&nbsp;";
                     }
                     $flagInfoLine2 = true;
                     // set flag to print later the qualification descriptions if required
                     $info_save2 = $info;
                     //$list->printInfoLine($info);
                     $qual_mode = TRUE;
                 }
                 $evnt = $row[4];
                 // keep event ID
                 //$roundM = $row[13];
             }
             // ET new event
             //else {
             //	if ($roundM!=$row[13]){      // set up subtitle when merged round are separated
             //		  $flagSubtitle=true;       // set flag to print the subtitle later
             //	}
             //}
             $relay = AA_checkRelay($row[4]);
             // check, if this is a relay event
             $svm = AA_checkSVM($row[4]);
             // If round evaluated per heat, group results accordingly
             $order_heat = "";
             if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                 // eval per heat
                 $order_heat = "heatid, ";
             }
             $valid_result = "";
             // Order performance depending on discipline type
             if ($row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow]) {
                 $order_perf = "DESC";
             } else {
                 if ($row[3] == $cfgDisciplineType[$strDiscTypeJump]) {
                     if ($row[8] == 1) {
                         // with wind
                         $order_perf = "DESC, r.Info ASC";
                     } else {
                         // without wind
                         $order_perf = "DESC";
                     }
                 } else {
                     if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $order_perf = "DESC";
                         $valid_result = " AND (r.Info LIKE '%O%'" . " OR r.Leistung < 0)";
                     } else {
                         $order_perf = "ASC";
                     }
                 }
             }
             $sqlSeparate = '';
             if (($catMerged || $eventMerged) & $heatSeparate) {
                 if ($row[0] > 0 && $row[13] != NULL) {
                     $roundSQL = '';
                     if (empty($limitRankSQL) && empty($valid_result)) {
                         $sqlSeparate = " ss.RundeZusammen = " . $row[0];
                     } else {
                         if (empty($limitRankSQL)) {
                             $valid_result = substr($valid_result, 4, strlen($valid_result));
                         } elseif (empty($valid_result)) {
                             $limitRankSQL = substr($limitRankSQL, 4, strlen($limitRankSQL));
                         }
                         $sqlSeparate = " AND ss.RundeZusammen = " . $row[0];
                     }
                 }
             }
             // get all results ordered by ranking; for invalid results (Rang=0), the
             // rank is set to max_rank to put them to the end of the list.
             $max_rank = 999999999;
             $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, (If (r.Leistung = -98, -8,r.Leistung))) * -1), r.Leistung)";
             $order = $order_heat;
             if ($relay == FALSE) {
                 if ($athleteCat) {
                     $order = $orderAthleteCat . $order_heat;
                 }
                 $query = "SELECT ss.xSerienstart, \r\n\t\t\t\t\t\t\t IF(ss.Rang=0, {$max_rank}, ss.Rang) AS rank, \r\n\t\t\t\t\t\t\t ss.Qualifikation, \r\n\t\t\t\t\t\t\t " . $sql_leistung . " AS leistung_neu, \r\n\t\t\t\t\t\t\t r.Info, \r\n\t\t\t\t\t\t\t s.Bezeichnung, \r\n\t\t\t\t\t\t\t s.Wind, \r\n\t\t\t\t\t\t\t r.Punkte, \r\n\t\t\t\t\t\t\t IF('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)), \r\n\t\t\t\t\t\t\t at.Name, \r\n\t\t\t\t\t\t\t at.Vorname, \r\n\t\t\t\t\t\t\t at.Jahrgang, \r\n\t\t\t\t\t\t\t LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n\t\t\t\t\t\t\t IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land, \r\n\t\t\t\t\t\t\t at.xAthlet, \r\n\t\t\t\t\t\t\t ru.Datum, \r\n\t\t\t\t\t\t\t ru.Startzeit ,\r\n\t\t\t\t\t\t\t ss.RundeZusammen,\r\n\t\t\t\t\t\t\t ru.xRunde,  \r\n\t\t\t\t\t\t\t k.Name , \r\n\t\t\t\t\t\t\t k1.Name , \t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t k1.Anzeige ,\r\n                             ss.Bemerkung ,\r\n                              w.Punkteformel,\r\n                             w.info,\r\n                             a.Startnummer   \r\n\t\t\t\t\t\tFROM athletica.serie AS s USE INDEX(Runde)\r\n\t\t\t\t   LEFT JOIN athletica.serienstart AS ss USING(xSerie) \r\n\t\t\t\t   LEFT JOIN athletica.resultat AS r USING(xSerienstart) \r\n\t\t\t\t   LEFT JOIN athletica.start AS st ON(ss.xStart = st.xStart) \r\n\t\t\t\t   LEFT JOIN athletica.anmeldung AS a USING(xAnmeldung) \r\n\t\t\t\t   LEFT JOIN athletica.athlet AS at USING(xAthlet) \r\n\t\t\t\t   LEFT JOIN athletica.verein AS v USING(xVerein) \r\n\t\t\t\t   LEFT JOIN athletica.region AS re ON(at.xRegion = re.xRegion) \r\n\t\t\t\t   LEFT JOIN athletica.team AS t ON(a.xTeam = t.xTeam) \r\n\t\t\t\t   LEFT JOIN athletica.runde AS ru ON(s.xRunde = ru.xRunde) \r\n\t\t\t\t   LEFT JOIN athletica.wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n\t\t\t\t   LEFT JOIN athletica.kategorie AS k On (w.xKategorie= k.xKategorie)\r\n\t\t\t\t   LEFT JOIN athletica.kategorie AS k1 ON (a.xKategorie = k1.xKategorie)   \r\n\t\t\t\t\t   WHERE " . $roundSQL . " \r\n\t\t\t\t\t   " . $limitRankSQL . " \r\n\t\t\t\t\t   " . $valid_result . " \r\n\t\t\t\t\t   " . $sqlSeparate . " \r\n\t\t\t\t\t   " . $selectionHeats . "  \r\n\t\t\t\t\tORDER BY " . $order . "   \t\t\t\t\t         \r\n\t\t\t\t\t\t\t rank, \r\n\t\t\t\t\t\t\t at.Name, \r\n\t\t\t\t\t\t\t at.Vorname,\r\n\t\t\t\t\t\t\t leistung_neu " . $order_perf;
             } else {
                 // relay event
                 $query = "SELECT ss.xSerienstart,           \t\t\t\t\t\t\r\n\t\t\t\t\t\t\t IF(r.Leistung < 0 , {$max_rank}, if (ss.Rang=0, {$max_rank}-1, ss.Rang)) AS rank, \r\n\t\t\t\t\t\t\t ss.Qualifikation, \r\n\t\t\t\t\t\t\t " . $sql_leistung . " AS leistung_neu, \r\n\t\t\t\t\t\t\t r.Info, \r\n\t\t\t\t\t\t\t s.Bezeichnung, \r\n\t\t\t\t\t\t\t s.Wind, \r\n\t\t\t\t\t\t\t r.Punkte, \r\n\t\t\t\t\t\t\t IF('" . $svm . "', t.Name, v.Name), \r\n\t\t\t\t\t\t\t sf.Name, \r\n\t\t\t\t\t\t\t LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n\t\t\t\t\t\t\t st.xStart, \r\n\t\t\t\t\t\t\t ru.Datum, \r\n\t\t\t\t\t\t\t ru.Startzeit, \r\n\t\t\t\t\t\t\t ss.RundeZusammen,\r\n\t\t\t\t\t\t\t ru.xRunde,\r\n\t\t\t\t\t\t\t k.Name ,\r\n                             ss.Bemerkung    \r\n\t\t\t\t\t\tFROM athletica.serie AS s USE INDEX(Runde) \r\n\t\t\t\t   LEFT JOIN athletica.serienstart AS ss USING(xSerie) \r\n\t\t\t\t   LEFT JOIN athletica.resultat AS r USING(xSerienstart) \r\n\t\t\t\t   LEFT JOIN athletica.start AS st ON(ss.xStart = st.xStart) \r\n\t\t\t\t   LEFT JOIN athletica.staffel AS sf USING(xStaffel) \r\n\t\t\t\t   LEFT JOIN athletica.verein AS v USING(xVerein) \r\n\t\t\t\t   LEFT JOIN athletica.team AS t ON(sf.xTeam = t.xTeam) \r\n\t\t\t\t   LEFT JOIN athletica.runde AS ru ON(s.xRunde = ru.xRunde) \r\n\t\t\t\t   LEFT JOIN athletica.wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n\t\t\t\t   LEFT JOIN athletica.kategorie AS k On (w.xKategorie= k.xKategorie) \r\n\t\t\t\t\t    WHERE " . $roundSQL . "  \r\n\t\t\t\t\t  " . $limitRankSQL . " \r\n\t\t\t\t\t  " . $valid_result . " \r\n\t\t\t\t\t  " . $sqlSeparate . "  \r\n\t\t\t\t\tGROUP BY r.xSerienstart \r\n\t\t\t\t\tORDER BY " . $order . " \r\n\t\t\t\t\t\t\t rank, \r\n\t\t\t\t\t\t\t r.Leistung \r\n\t\t\t\t\t\t\t " . $order_perf . ", \r\n\t\t\t\t\t\t\t sf.Name;";
             }
             $res = mysql_query($query);
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 if (mysql_num_rows($res) == 0) {
                     continue;
                 }
                 // initialize variables
                 $heat = '';
                 $h = 0;
                 $info = '';
                 $id = '';
                 $r = '';
                 $count_rank = 0;
                 $perf_save = '';
                 //$list->startList();
                 $nr = 0;
                 $atCat = '';
                 // process every result
                 while ($row_res = mysql_fetch_array($res)) {
                     if ($flagSubtitle) {
                         $nr = 0;
                         if ($heatSeparate) {
                             if ($relay) {
                                 $list->printSubTitle($row_res[16], $row[2], $roundName);
                             } else {
                                 if (!$athleteCat) {
                                     $list->printSubTitle($row_res[19], $row[2], $roundName);
                                 }
                             }
                         } else {
                             if (!$athleteCat) {
                                 $list->printSubTitle($row[1], $row[2], $roundName);
                             }
                         }
                         $flagSubtitle = false;
                     }
                     if (!$athleteCat) {
                         if ($flagInfoLine1) {
                             $list->printInfoLine($info_save1);
                             $flagInfoLine1 = false;
                         }
                     }
                     if (!$athleteCat) {
                         if ($flagInfoLine2) {
                             $list->printInfoLine($info_save2);
                             $flagInfoLine2 = false;
                         }
                     }
                     $row_res[3] = $row_res[3] == 1 || $row_res[3] == 2 || $row_res[3] == 3 || $row_res[3] == 4 ? $row_res[3] * -1 : ($row_res[3] == 9 ? -99 : $row_res[3]);
                     if ($row_res[0] != $id) {
                         if ($h == 0 || $row_res[5] != $heat && $eval == $cfgEvalType[$strEvalTypeHeat] || $athleteCat && $row_res[21] != $atCat) {
                             $count_rank = 0;
                             $nr = 0;
                             // heat name
                             if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                                 if (empty($type)) {
                                     // no round type defined
                                     $type = $strFinalround . " ";
                                 }
                                 $title = $type . $row_res[5];
                                 // heat name with nbr.
                             } else {
                                 $title = $type;
                                 // heat name withour nbr.
                             }
                             $title = trim($title);
                             // wind per heat
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeHeat]) {
                                 $heatwind = $row_res[6];
                                 // wind per heat
                             } else {
                                 $heatwind = '';
                                 // no wind
                             }
                             $wind = FALSE;
                             if ($row[8] == 1 && $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                 $wind = TRUE;
                             }
                             // add column header 'points' if required
                             $points = FALSE;
                             if ($row[7] != '0') {
                                 $points = TRUE;
                             }
                             if ($show_efforts == 'sb_pb') {
                                 $base_perf = true;
                             }
                             if ($athleteCat && !$relay) {
                                 if ($formaction == 'print') {
                                     if ($row_res[20] != $atCatName) {
                                         $list->printSubTitle($row_res[20], $row[2], $roundName, $row_res[24]);
                                         $atCatName_keep = $atCatName;
                                         if ($flagInfoLine1) {
                                             $list->printInfoLine($info_save1);
                                             $flagInfoLine1 = false;
                                         }
                                         if ($flagInfoLine2) {
                                             $list->printInfoLine($info_save2);
                                             $flagInfoLine2 = false;
                                         }
                                     }
                                 }
                             }
                             $list->startList();
                             $list->printHeaderLine($title, $relay, $points, $wind, $heatwind, $row[11], $svm, $base_perf, $qual_mode);
                             if ($athleteCat && !$relay) {
                                 if ($formaction == 'view') {
                                     if ($row_res[20] != $atCatName) {
                                         $list->printSubTitle($row_res[20], $row[2], $roundName, $row_res[24]);
                                         $atCatName_keep = $atCatName;
                                         if ($flagInfoLine1) {
                                             $list->printInfoLine($info_save1, $athleteCat);
                                             $flagInfoLine1 = false;
                                         }
                                         if ($flagInfoLine2) {
                                             $list->printInfoLine($info_save2, $athleteCat);
                                             $flagInfoLine2 = false;
                                         }
                                     }
                                 }
                             }
                             $heat = $row_res[5];
                             // keep heat description
                             $atCat = $row_res[21];
                             // keep athlete category
                             $h++;
                             // increment if evaluation per heat
                         }
                         $count_rank++;
                         // rank
                         if ($row_res[1] == $max_rank || $row_res[1] == $max_rank - 1 || $r == $row_res[1] && $heat_keep == $row_res[5]) {
                             // same rank as previous
                             $rank = '';
                         } else {
                             $rank = $row_res[1];
                         }
                         $r = $row_res[1];
                         // keep rank
                         $heat_keep = $row_res[5];
                         // keep rank
                         $atCatName = $row_res[20];
                         // keep athlete category name
                         // name
                         $name = $row_res[9];
                         if ($relay == FALSE) {
                             $name = $name . " " . $row_res[10];
                         }
                         // year of birth
                         if ($relay == FALSE) {
                             $year = AA_formatYearOfBirth($row_res[11]);
                         } else {
                             $year = '';
                         }
                         // year of birth
                         if ($relay == FALSE) {
                             $land = $row_res[13] != '' && $row_res[13] != '-' ? $row_res[13] : '';
                         } else {
                             $year = '';
                         }
                         // performance
                         if ($row_res[3] < 0) {
                             // invalid result
                             foreach ($cfgInvalidResult as $value) {
                                 if ($value['code'] == $row_res[3]) {
                                     $perf = $value['short'];
                                 }
                             }
                         } else {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                 $perf = AA_formatResultMeter($row_res[3]);
                             } else {
                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                     $perf = AA_formatResultTime($row_res[3], true, true);
                                 } else {
                                     $perf = AA_formatResultTime($row_res[3], true);
                                 }
                             }
                         }
                         $qual = '';
                         if ($row_res[2] > 0) {
                             // Athlete qualified
                             foreach ($cfgQualificationType as $qtype) {
                                 if ($qtype['code'] == $row_res[2]) {
                                     $qual = $qtype['token'];
                                 }
                             }
                         }
                         // ET athlete qualified
                         // points for performance
                         $points = '';
                         if ($row[7] != '0') {
                             $points = $row_res[7];
                         }
                         // wind info
                         $wind = '';
                         $secondResult = false;
                         if ($r != $max_rank) {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] && $row[8] == 1) {
                                 $wind = $row_res[4];
                                 //
                                 // if wind bigger than max wind (2.0) show the next best result without wind too
                                 //
                                 if ($wind > 2) {
                                     $res_wind = mysql_query("\r\n\t\t\t\t\t\t\t\t\t\tSELECT Info, Leistung FROM\r\n\t\t\t\t\t\t\t\t\t\t\tresultat\r\n\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\t\txSerienstart = {$row_res['0']}\r\n\t\t\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\t\t\t\tLeistung ASC");
                                     if (mysql_errno() > 0) {
                                         // DB error
                                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                     } else {
                                         while ($row_wind = mysql_fetch_array($res_wind)) {
                                             if ($row_wind[0] <= 2) {
                                                 $secondResult = true;
                                                 $wind2 = $row_wind[0] . ")";
                                                 $perf2 = "(" . AA_formatResultMeter($row_wind[1]);
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                     $wind = $row_res[6];
                                 }
                             }
                         }
                         // ioc country code
                         $ioc = '';
                         if ($relay == false) {
                             $ioc = $row_res[13];
                         }
                         //show performances from base
                         if ($show_efforts == 'sb_pb' && $relay == false) {
                             $saison = $_SESSION['meeting_infos']['Saison'];
                             if ($saison == '') {
                                 $saison = "O";
                                 //if no saison is set take outdoor
                             }
                             $sql = "SELECT \r\n\t\t\t\t\t\t\t\t\tseason_effort\r\n\t\t\t\t\t\t\t\t\t, DATE_FORMAT(season_effort_date, '%d.%m.%Y') AS sb_date\r\n\t\t\t\t\t\t\t\t\t, season_effort_event\r\n\t\t\t\t\t\t\t\t\t, best_effort\r\n\t\t\t\t\t\t\t\t\t, DATE_FORMAT(best_effort_date, '%d.%m.%Y') AS pb_date\r\n\t\t\t\t\t\t\t\t\t, best_effort_event\r\n\t\t\t\t\t\t\t\t\t, season\r\n\t\t\t\t\t\t\t\t\t, xAnmeldung\r\n\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\tathletica.base_performance\r\n\t\t\t\t\t\tLEFT JOIN \r\n\t\t\t\t\t\t\tathletica.base_athlete USING (id_athlete)\r\n\t\t\t\t\t\tLEFT JOIN \r\n\t\t\t\t\t\t\tathletica.disziplin_" . $_COOKIE['language'] . " ON (discipline = Code)\r\n\t\t\t\t\t\tLEFT JOIN \r\n\t\t\t\t\t\t\tathletica.athlet ON (license = Lizenznummer)\r\n\t\t\t\t\t\tLEFT JOIN\r\n\t\t\t\t\t\t\tathletica.anmeldung USING(xAthlet) \r\n\t\t\t\t\t\tWHERE \r\n\t\t\t\t\t\t\tathlet.xAthlet = {$row_res['14']}\r\n\t\t\t\t\t\t\tAND xDisziplin = {$row['12']}\r\n\t\t\t\t\t\t\tAND season = '{$saison}' \r\n\t\t\t\t\t\t\tAND xMeeting = " . $_COOKIE['meeting_id'] . ";";
                             $res_perf = mysql_query($sql);
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 if ($res_perf) {
                                     $row_perf = mysql_fetch_array($res_perf);
                                     $is_jump = $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh];
                                     $order = $is_jump ? 'DESC' : 'ASC';
                                     $best_previous = '';
                                     $previous_date = '';
                                     if ($row_perf !== false) {
                                         $best_previous = AA_getBestPrevious($row[12], $row_perf['xAnmeldung'], $order, $row_res['Datum'], $row_res['Startzeit'], &$previous_date);
                                     }
                                     if ($is_jump) {
                                         $sb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['season_effort']));
                                         $pb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['best_effort']));
                                         $bp_perf = AA_formatResultMeter(str_replace(".", "", $best_previous));
                                         if ($bp_perf > 0 && $bp_perf > $sb_perf) {
                                             $sb_perf = $bp_perf;
                                             $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($bp_perf > 0 && $bp_perf > $pb_perf) {
                                             $pb_perf = $bp_perf;
                                             $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         //highlight sb or pb if new performance is better
                                         if (is_numeric($perf)) {
                                             //prevent special-codes (disq, n.a. usw)
                                             if ($formaction != 'print') {
                                                 if ($pb_perf != '' && $perf > $pb_perf) {
                                                     $perf = "<b>PB {$perf}</b> ";
                                                 } else {
                                                     if ($sb_perf != '' && $perf > $sb_perf) {
                                                         $perf = "<b>SB {$perf}</b>";
                                                     }
                                                 }
                                             } else {
                                                 if ($pb_perf != '' && $perf > $pb_perf) {
                                                     $perf = "<b>PB</b> {$perf}";
                                                 } else {
                                                     if ($sb_perf != '' && $perf > $sb_perf) {
                                                         $perf = "<b>SB</b> {$perf}";
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         //convert performance-time to milliseconds
                                         $timepices = explode(":", $row_perf['season_effort']);
                                         $season_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                         $timepices = explode(":", $row_perf['best_effort']);
                                         $best_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                         $previous_effort = intval($best_previous);
                                         if ($previous_effort > 0 && $previous_effort < $season_effort) {
                                             $season_effort = $previous_effort;
                                             $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($previous_effort > 0 && $previous_effort < $best_effort) {
                                             $best_effort = $previous_effort;
                                             $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                             $sb_perf = AA_formatResultTime($season_effort, true, true);
                                             $pb_perf = AA_formatResultTime($best_effort, true, true);
                                         } else {
                                             $sb_perf = AA_formatResultTime($season_effort, true);
                                             $pb_perf = AA_formatResultTime($best_effort, true);
                                         }
                                         if ($formaction != 'print') {
                                             //highlight sb or pb if new performance is better
                                             if ($pb_perf != '' && $perf < $pb_perf) {
                                                 $perf = "<b>PB {$perf}</b>";
                                             } else {
                                                 if ($sb_perf != '' && $perf < $sb_perf) {
                                                     $perf = "<b>SB {$perf}</b>";
                                                 }
                                             }
                                         } else {
                                             if ($pb_perf != '' && $perf < $pb_perf) {
                                                 $perf = "<b>PB</b> {$perf}";
                                             } else {
                                                 if ($sb_perf != '' && $perf < $sb_perf) {
                                                     $perf = "<b>SB</b> {$perf}";
                                                 }
                                             }
                                         }
                                     }
                                     if (!empty($row_perf['season_effort'])) {
                                         $sb = "<a href=\"#\" class=\"info\">{$sb_perf}<span>{$row_perf['sb_date']}<br>{$row_perf['season_effort_event']}</span></a>";
                                     } else {
                                         $sb = "&nbsp;";
                                     }
                                     if (!empty($row_perf['best_effort'])) {
                                         $pb = "<a href=\"#\" class=\"info\">{$pb_perf}<span>{$row_perf['pb_date']}<br>{$row_perf['best_effort_event']}</span></a>";
                                     } else {
                                         $pb = "&nbsp;";
                                     }
                                 }
                             }
                         }
                         if ($heatSeparate) {
                             $rank = $count_rank;
                             if ($perf == $perf_save || $row_res[3] < 0) {
                                 // same rank or invalid result
                                 $rank = '';
                             }
                         }
                         if ($athleteCat && !$relay) {
                             $nr++;
                             if ($rank != '') {
                                 if ($formaction == "print") {
                                     $rank = $nr . ". (" . $rank . ")";
                                 } else {
                                     $rank = $nr . " (" . $rank . ")";
                                 }
                             }
                         } else {
                             if ($formaction == "print") {
                                 if ($rank != '') {
                                     $rank .= ".";
                                 }
                             }
                         }
                         if ($relay) {
                             $remark = $row_res[17];
                         } else {
                             $remark = $row_res[22];
                         }
                         $list->printLine($rank, $name, $year, $row_res[8], $perf, $wind, $points, $qual, $ioc, $sb, $pb, $qual_mode, $athleteCat, $remark);
                         if ($secondResult) {
                             $list->printLine("", "", "", "", $perf2, $wind2, "", "", "", "", "", $qual_mode);
                         }
                         $perf_save = $perf;
                         // keep performance
                         //
                         // if relay, show started ahtletes in right order under the result
                         //
                         if ($relay) {
                             if ($row_res[14] > 0) {
                                 $sqlRound = $row_res[14];
                             } else {
                                 $sqlRound = $row[0];
                             }
                             $res_at = mysql_query("\r\n\t\t\t\t\t\t\t\tSELECT at.Vorname, at.Name, at.Jahrgang FROM\r\n\t\t\t\t\t\t\t\t\tathletica.staffelathlet as sfat\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN athletica.start as st ON sfat.xAthletenstart = st.xStart\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN athletica.anmeldung as a USING(xAnmeldung)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN athletica.athlet as at USING(xAthlet)\r\n\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\tsfat.xStaffelstart = {$row_res['11']}\r\n\t\t\t\t\t\t\t\tAND\tsfat.xRunde = {$sqlRound} \r\n\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\t\tsfat.Position\r\n\t\t\t\t\t\t\t\tLIMIT {$row['10']}\r\n\t\t\t\t\t\t");
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 $text_at = "";
                                 while ($row_at = mysql_fetch_array($res_at)) {
                                     $text_at .= $row_at[1] . " " . $row_at[0] . " " . AA_formatYearOfBirth($row_at[2]) . " / ";
                                 }
                                 $text_at = substr($text_at, 0, strlen($text_at) - 2);
                                 $text_at = trim($text_at) != '' ? '(' . $text_at . ')' : '';
                                 $list->printAthletesLine($text_at);
                             }
                         }
                         //
                         // if biglist, show all attempts
                         //
                         if ($biglist) {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                 $query_sort = $row[3] == $cfgDisciplineType[$strDiscTypeHigh] ? "ORDER BY Leistung ASC" : "";
                                 $res_att = mysql_query("\r\n\t\t\t\t\t\t\t\tSELECT * FROM \r\n\t\t\t\t\t\t\t\t\tathletica.resultat \r\n\t\t\t\t\t\t\t\tWHERE xSerienstart = {$row_res['0']}\r\n\t\t\t\t\t\t\t\t" . $query_sort . "\r\n\t\t\t\t\t\t\t\t");
                                 if (mysql_errno() > 0) {
                                     // DB error
                                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                 } else {
                                     $text_att = "";
                                     while ($row_att = mysql_fetch_array($res_att)) {
                                         if ($row_att['Leistung'] < 0) {
                                             $perf3 = $row_att['Leistung'];
                                             if ($perf3 == $GLOBALS['cfgMissedAttempt']['db']) {
                                                 // $perf3 = '-';
                                                 $perf3 = $GLOBALS['cfgMissedAttempt']['code'];
                                             } elseif ($perf3 == $GLOBALS['cfgMissedAttempt']['dbx']) {
                                                 $perf3 = $GLOBALS['cfgMissedAttempt']['codeX'];
                                             }
                                             foreach ($cfgInvalidResult as $value) {
                                                 if ($value['code'] == $perf3) {
                                                     $text_att .= $value['short'];
                                                 }
                                             }
                                             $text_att .= " / ";
                                         } else {
                                             $text_att .= $row_att['Leistung'] == '-' ? '-' : AA_formatResultMeter($row_att['Leistung']);
                                             if ($saison == "O" || $saison == "I" && $row[3] != $cfgDisciplineType[$strDiscTypeJump]) {
                                                 // outdoor  or (indoor and not jump)
                                                 if ($row_att['Info'] != "-" && !empty($row_att['Info']) && $row[3] != $cfgDisciplineType[$strDiscTypeThrow]) {
                                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                                         $text_att .= " , " . $row_att['Info'];
                                                     } else {
                                                         if ($row[8] != 0) {
                                                             $text_att .= " , " . $row_att['Info'];
                                                         }
                                                     }
                                                 } elseif ($row_att['Info'] == "-" && $row[3] != $cfgDisciplineType[$strDiscTypeThrow] && $row_att['Leistung'] > 0) {
                                                     $text_att .= " , " . $row_att['Info'];
                                                 }
                                             }
                                             $text_att .= " / ";
                                         }
                                     }
                                     $text_att = substr($text_att, 0, strlen($text_att) - 2);
                                     $list->printAthletesLine("{$strAttempts}: ( {$text_att} )");
                                 }
                             }
                         }
                     }
                     // ET athlete processed
                     $id = $row_res[0];
                     // keep current athletes ID
                     if ($relay) {
                         $catM = $row_res[16];
                     } else {
                         $catM = $row_res[19];
                     }
                     // keep merged category
                 }
                 // END WHILE result lines
                 mysql_free_result($res);
                 $list->endList();
             }
             // ET DB error result rows
             $cat = $row[1];
             // keep category
         }
         // END WHILE event rounds
         mysql_free_result($results);
         $list->endPage();
         // end HTML page for printing
         $list->content .= $cfgHtmlFooter;
         $list->content .= " </div ></div>";
         $list->content .= $cfgHtmlEnd;
         if (!fwrite($fp, $list->content)) {
             AA_printErrorMsg($GLOBALS['strErrFileWriteFailed']);
             return;
         }
         fclose($fp);
     }
     // ET DB error event rounds
     // will not be uploaded the next time per ftp
     AA_UpdateStatusChanged($round);
 }
 function AA_rankinglist_Single($category, $event, $round, $formaction, $break, $cover, $biglist = false, $cover_timing = false, $date = '%', $show_efforts = 'none', $heatSeparate, $catFrom, $catTo, $discFrom, $discTo, $heatFrom, $heatTo, $athleteCat, $withStartnr, $ranklistAll, $ukc)
 {
     // anstead of remove the function "rankinglist ubs kids cup"", set $ukc for the moment false  --> later remove it perhaps
     // "rankinglist ubs kids cup" is solved in rankinglist_combined.lib.php
     $ukc = false;
     require './lib/cl_gui_page.lib.php';
     require './lib/cl_print_page.lib.php';
     require './lib/cl_export_page.lib.php';
     require './lib/common.lib.php';
     require './lib/results.lib.php';
     require './lib/utils.lib.php';
     if (AA_connectToDB() == FALSE) {
         // invalid DB connection
         return;
         // abort
     }
     if (AA_checkMeetingID() == FALSE) {
         // no meeting selected
         return;
         // abort
     }
     // check teamsm
     $teamsm = AA_checkTeamsm(0, 0);
     // set up ranking list selection
     $selection = '';
     $eventMerged = false;
     $catMerged = false;
     $flagSubtitle = false;
     $flagInfoLine1 = false;
     $flagInfoLine2 = false;
     $results_ukc = FALSE;
     $selectionHeats = '';
     $orderAthleteCat = '';
     $saison = $_SESSION['meeting_infos']['Saison'];
     if ($saison == '') {
         $saison = "O";
         //if no saison is set take outdoor
     }
     if ($round > 0) {
         // show a specific round
         $eventMerged = false;
         $sqlEvents = AA_getMergedEventsFromEvent($event);
         if ($sqlEvents != '') {
             $selection = "w.xWettkampf IN " . $sqlEvents . " AND ";
             $eventMerged = true;
         } else {
             $selection = "r.xRunde =" . $round . " AND ";
         }
     } elseif ($category == 0) {
         // show all disciplines for every category
         $catMerged = true;
     } elseif ($event == 0) {
         // show all disciplines for a specific category
         $catMerged = false;
         $mergedCat = AA_mergedCat($category);
         if ($mergedCat != '') {
             $selection = "w.xKategorie IN " . $mergedCat . " AND ";
             $catMerged = true;
         } else {
             $selection = "w.xKategorie =" . $category . " AND ";
         }
     } else {
         if ($round == 0) {
             // show all rounds for a specific event
             $eventMerged = false;
             $sqlEvents = AA_getMergedEventsFromEvent($event);
             if ($sqlEvents != '') {
                 $selection = "w.xWettkampf IN " . $sqlEvents . " AND ";
                 $eventMerged = true;
             } else {
                 $selection = "w.xWettkampf =" . $event . " AND ";
             }
         }
     }
     if ($catFrom > 0) {
         //
         $getSortCat = AA_getSortCat($catFrom, $catTo);
         if ($getSortCat[0]) {
             if ($catTo > 0) {
                 $selection = "k.Anzeige >=" . $getSortCat[$catFrom] . " AND k.Anzeige <=" . $getSortCat[$catTo] . " AND ";
             } else {
                 $selection = "k.Anzeige =" . $getSortCat[$catFrom] . " AND ";
             }
         }
     }
     if ($discFrom > 0) {
         //
         $getSortDisc = AA_getSortDisc($discFrom, $discTo);
         if ($getSortDisc[0]) {
             if ($discTo > 0) {
                 $selection .= "d.Anzeige >=" . $getSortDisc[$discFrom] . " AND d.Anzeige <=" . $getSortDisc[$discTo] . " AND ";
             } else {
                 $selection .= "d.Anzeige =" . $getSortDisc[$discFrom] . " AND ";
             }
         }
     }
     if ($heatFrom > 0) {
         $selectionHeats = ' AND s.xSerie >= ' . $heatFrom . ' AND s.xSerie <= ' . $heatTo . ' ';
     }
     if ($athleteCat) {
         $orderAthleteCat = ' k1.Anzeige, ';
     }
     if ($catMerged & !$heatSeparate || $eventMerged & !$heatSeparate) {
         // get event rounds from DB
         if ($ukc) {
             $selection = " (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") AND ";
         }
         if ($teamsm) {
             $sql = "SELECT \r\n                    group_concat(r.xRunde)\r\n                    , k.Name\r\n                    , d.Name\r\n                    , d.Typ\r\n                    , w.xWettkampf\r\n                    , r.QualifikationSieger\r\n                    , r.QualifikationLeistung\r\n                    , w.Punkteformel\r\n                    , w.Windmessung\r\n                    , r.Speakerstatus\r\n                    , d.Staffellaeufer\r\n                    , CONCAT(DATE_FORMAT(r.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(r.Startzeit, '{$cfgDBtimeFormat}'))     \r\n                    , w.xDisziplin  \r\n                    , w.info         \r\n                FROM\r\n                    wettkampf AS w\r\n                    LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n                      LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                      LEFT JOIN runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n                WHERE " . $selection . "\r\n                w.xMeeting = " . $_COOKIE['meeting_id'] . "     \r\n                AND r.Status = " . $cfgRoundStatus['results_done'] . " \r\n                AND r.Datum LIKE '" . $date . "'\r\n                GROUP BY w.xWettkampf\r\n                ORDER BY\r\n                    k.Anzeige\r\n                    , d.Anzeige\r\n                    , r.Datum\r\n                    , r.Startzeit";
             $results = mysql_query($sql);
         } else {
             $sql = "SELECT \r\n                r.xRunde\r\n                , k.Name\r\n                , d.Name\r\n                , d.Typ\r\n                , w.xWettkampf\r\n                , r.QualifikationSieger\r\n                , r.QualifikationLeistung\r\n                , w.Punkteformel\r\n                , w.Windmessung\r\n                , r.Speakerstatus\r\n                , d.Staffellaeufer\r\n                , CONCAT(DATE_FORMAT(r.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(r.Startzeit, '{$cfgDBtimeFormat}'))\r\n                , w.xDisziplin  \r\n                , w.info          \r\n            FROM\r\n                wettkampf AS w\r\n                LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n                  LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                  LEFT JOIN runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n            WHERE " . $selection . "\r\n            w.xMeeting = " . $_COOKIE['meeting_id'] . "     \r\n            AND r.Status = " . $cfgRoundStatus['results_done'] . " \r\n            AND r.Datum LIKE '" . $date . "'\r\n            ORDER BY\r\n                k.Anzeige\r\n                , d.Anzeige\r\n                , r.Datum\r\n                , r.Startzeit";
             $results = mysql_query($sql);
         }
     } else {
         // heats separate
         $sql = "SELECT DISTINCT \r\n                r.xRunde , \r\n                k.Name , \r\n                d.Name , \r\n                d.Typ , \r\n                w.xWettkampf , \r\n                r.QualifikationSieger , \r\n                r.QualifikationLeistung , \r\n                w.Punkteformel , \r\n                w.Windmessung , \r\n                r.Speakerstatus , \r\n                d.Staffellaeufer , \r\n                CONCAT(DATE_FORMAT(r.Datum,'%d.%m.%y'), \r\n                ' ', \r\n                TIME_FORMAT(r.Startzeit, '%H:%i')) ,\r\n                w.xDisziplin ,  \r\n                rs.Hauptrunde,\r\n                w.info     \r\n            FROM \r\n                wettkampf AS w \r\n                LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie) \r\n                LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                LEFT JOIN runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n                LEFT JOIN rundenset as rs ON (r.xRunde=rs.xRunde )           \r\n            WHERE \r\n                " . $selection . "  \r\n                w.xMeeting  = " . $_COOKIE['meeting_id'] . " \r\n                AND r.Status = 4  \r\n                AND r.Datum LIKE '%' \r\n            ORDER BY\r\n                k.Anzeige\r\n                , d.Anzeige\r\n                , r.Datum\r\n                , r.Startzeit";
         $results = mysql_query($sql);
     }
     if (mysql_errno() > 0) {
         // DB error
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $limitRankSQL = "";
         $limitRank = false;
         if ($_GET['limitRank'] == "yes") {
             // check if ranks are limited, but limitRankSQL will set only if export is pressed
             if (!empty($_GET['limitRankFrom']) && !empty($_GET['limitRankTo'])) {
                 $limitRank = true;
             }
         }
         // start a new HTML display page
         if ($formaction == 'view' || $formaction == 'speaker') {
             // display page
             $list = new GUI_RankingList($_COOKIE['meeting']);
             $list->printPageTitle("{$strRankingLists} " . $_COOKIE['meeting']);
         } elseif ($formaction == "print") {
             $list = new PRINT_RankingList($_COOKIE['meeting']);
             if ($cover == true) {
                 // print cover page
                 $list->printCover($GLOBALS['strResults'], $cover_timing);
             }
         } elseif ($formaction == "exportpress") {
             $list = new EXPORT_RankingListPress($_COOKIE['meeting'], 'txt');
             if ($limitRank) {
                 $limitRankSQL = " AND ss.Rang <= " . $_GET['limitRankTo'] . " AND ss.Rang >= " . $_GET['limitRankFrom'] . " ";
             }
         } elseif ($formaction == "exportdiplom") {
             $list = new EXPORT_RankingListDiplom($_COOKIE['meeting'], 'csv');
             if ($limitRank) {
                 $limitRankSQL = " AND ss.Rang <= " . $_GET['limitRankTo'] . " AND ss.Rang >= " . $_GET['limitRankFrom'] . " ";
             }
         }
         // initialize variables
         $cat = '';
         $evnt = 0;
         if (mysql_num_rows($results) == 0) {
             echo "<br><br><b><blockquote>{$strErrNoResults}</blockquote></b>";
         }
         $rounds = array();
         $catUkc = "";
         $roundsUkc = array();
         $discUkc = "";
         $roundsInfo = array();
         $mergedRounds = '';
         while ($row = mysql_fetch_row($results)) {
             if (!$teamsm) {
                 $mergedRounds = AA_getMergedRounds($row[0]);
             }
             if (!empty($mergedRounds)) {
                 if ($pos = strpos($mergedRounds, $row[0])) {
                     $rounds[$i] = $row[0];
                     if ($heatSeparate) {
                         if (!empty($row[14])) {
                             $roundsInfo[$row[0]] .= $row[14] . " / ";
                         }
                     } else {
                         if (!empty($row[13])) {
                             $roundsInfo[$row[0]] .= $row[13] . " / ";
                         }
                     }
                 } else {
                     if (!empty($row[13])) {
                         $roundsInfo[$row[0]] .= $row[13] . " / ";
                     }
                 }
             }
             if ($row[2] != $discUkc) {
                 $roundsUkc[$row[1]][] = $row[0];
             }
             $discUkc = $row[2];
         }
         $results = mysql_query($sql);
         if (mysql_errno() > 0) {
             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
         }
         while ($row = mysql_fetch_row($results)) {
             // for a combined event, the rounds are merged, so jump until the next event
             if ($cRounds > 1) {
                 $cRounds--;
                 continue;
             }
             if ($ukc) {
                 $catUkc = $row[1];
                 $rounds_in = "";
                 for ($i = 0; $i < 3; $i++) {
                     if (!empty($roundsUkc[$catUkc][$i])) {
                         $rounds_in .= $roundsUkc[$catUkc][$i] . ",";
                     }
                 }
                 $rounds_in = substr($rounds_in, 0, strlen($rounds_in) - 1);
                 if (!empty($r1)) {
                 }
                 $roundSQL = "s.xRunde IN ({$rounds_in}) ";
                 $GroupByUkc = " Group By at.xAthlet, w.xDisziplin ";
             } else {
                 $roundSQL = "s.xRunde = {$row['0']}";
                 $GroupByUkc = "";
             }
             if ($teamsm) {
                 $roundSQL = "s.xRunde IN ({$row['0']}) ";
             }
             $cRounds = 0;
             // check page  break
             if (is_a($list, "PRINT_RankingList") && $cat != '' && ($break == 'discipline' || $break == 'category' && $row[1] != $cat)) {
                 $list->insertPageBreak();
             }
             if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeRelay]) {
                 $eval = $cfgEvalType[$strEvalTypeHeat];
             } else {
                 $eval = $cfgEvalType[$strEvalTypeAll];
             }
             $roundName = '';
             $type = '';
             if ($teamsm) {
                 $res = mysql_query("\r\n                SELECT\r\n                    rt.Name\r\n                    , rt.Typ\r\n                    , rt.Wertung\r\n                FROM\r\n                    runde\r\n                    LEFT JOIN rundentyp_" . $_COOKIE['language'] . " AS rt ON (rt.xRundentyp = runde.xRundentyp)\r\n                WHERE \r\n                    runde.xRunde IN ({$row['0']})             \r\n            ");
             } else {
                 $res = mysql_query("\r\n                SELECT\r\n                    rt.Name\r\n                    , rt.Typ\r\n                    , rt.Wertung\r\n                FROM\r\n                    runde\r\n                    LEFT JOIN rundentyp_" . $_COOKIE['language'] . " AS rt ON (rt.xRundentyp = runde.xRundentyp)\r\n                WHERE \r\n                    runde.xRunde = {$row['0']}             \r\n                    ");
             }
             if (mysql_errno() > 0) {
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 if (mysql_num_rows($res) > 0) {
                     $row_rt = mysql_fetch_row($res);
                     if ($row_rt[1] == '0') {
                         $type = " ";
                         $row_rt[0] = '';
                     } else {
                         $type = $row_rt[0] . " ";
                     }
                     $eval = $row_rt[2];
                     if ($round != 0) {
                         // specific round selected
                         $roundName = $row_rt[0];
                     }
                 }
                 mysql_free_result($res);
             }
             if ($evnt != $row[4]) {
                 // if this is a combined event, dont fragment list by rounds
                 $combined = AA_checkCombined($row[4]);
                 // not selectet a specific round
                 if ($round == 0 && $combined && !$ukc) {
                     $res_c = mysql_query("SELECT \r\n                                r.xRunde\r\n                            FROM\r\n                                wettkampf as w\r\n                                LEFT JOIN runde as r ON (r.xWettkampf = w.xWettkampf)\r\n                            WHERE    \r\n                                w.xWettkampf = {$row['4']}\r\n                                AND r.status = 4");
                     if (mysql_errno() > 0) {
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         $cRounds = mysql_num_rows($res_c);
                         $roundSQL = "s.xRunde IN (";
                         while ($row_c = mysql_fetch_array($res_c)) {
                             $roundSQL .= $row_c[0] . ",";
                         }
                         $roundSQL = substr($roundSQL, 0, -1) . ")";
                     }
                 }
                 // set up category and discipline title information
                 $flagSubtitle = true;
                 // set flag to print the subtitle later
                 if ($formaction == 'speaker' && AA_getNextRound($row[4], $row[0]) == 0) {
                     // last round: show ceremony status
                     $list->printCeremonyStatus($row[0], $row[9]);
                 }
                 // print qualification mode if round selected
                 $info = '';
                 if ($round > 0 && ($row[5] > 0 || $row[6] > 0)) {
                     $info = "{$strQualification}: " . $row[5] . " {$strQualifyTop}, " . $row[6] . " {$strQualifyPerformance}";
                     $flagInfoLine1 = true;
                     // set flag to print later the qualification mode if round selected
                     $info_save1 = $info;
                     //$list->printInfoLine($info);
                     $qual_mode = TRUE;
                 }
                 // print qualification descriptions if required
                 $info = '';
                 if ($row[5] > 0 || $row[6] > 0) {
                     foreach ($cfgQualificationType as $qt) {
                         $info = $info . $qt['token'] . " =" . $qt['text'] . "&nbsp;&nbsp;&nbsp;";
                     }
                     $flagInfoLine2 = true;
                     // set flag to print later the qualification descriptions if required
                     $info_save2 = $info;
                     //$list->printInfoLine($info);
                     $qual_mode = TRUE;
                 }
                 $evnt = $row[4];
                 // keep event ID
             }
             // ET new event
             $relay = AA_checkRelay($row[4]);
             // check, if this is a relay event
             $svm = AA_checkSVM($row[4]);
             // If round evaluated per heat, group results accordingly
             $order_heat = "";
             if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                 // eval per heat
                 $order_heat = "heatid, ";
             }
             $valid_result = "";
             // Order performance depending on discipline type
             if ($row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow]) {
                 $order_perf = "DESC";
                 $order_perf2 = "DESC";
             } else {
                 if ($row[3] == $cfgDisciplineType[$strDiscTypeJump]) {
                     if ($row[8] == 1) {
                         // with wind
                         $order_perf = "DESC, r.Info ASC";
                         $order_perf2 = "DESC , r.Info ASC";
                     } else {
                         // without wind
                         $order_perf = "DESC";
                         $order_perf2 = "DESC";
                     }
                 } else {
                     if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                         $order_perf = "DESC";
                         $order_perf2 = "DESC";
                         $valid_result = " AND (r.Info LIKE '%O%'" . " OR r.Leistung < 0)";
                     } else {
                         $order_perf = "ASC";
                         $order_perf1 = "ASC";
                     }
                 }
             }
             $sqlSeparate = '';
             if (($catMerged || $eventMerged) & $heatSeparate) {
                 if ($row[0] > 0 && $row[13] != NULL) {
                     $roundSQL = '';
                     if (empty($limitRankSQL) && empty($valid_result)) {
                         $sqlSeparate = " ss.RundeZusammen = " . $row[0];
                     } else {
                         if (empty($limitRankSQL)) {
                             $valid_result = substr($valid_result, 4, strlen($valid_result));
                         } elseif (empty($valid_result)) {
                             $limitRankSQL = substr($limitRankSQL, 4, strlen($limitRankSQL));
                         }
                         $sqlSeparate = " AND ss.RundeZusammen = " . $row[0];
                     }
                 }
             }
             // get all results ordered by ranking; for invalid results (Rang=0), the
             // rank is set to max_rank to put them to the end of the list.
             $oder2 = "";
             $max_rank = 999999999;
             if ($ukc) {
                 $order2 = " d.Anzeige, rank, at.Name, at.Vorname, leistung_neu ";
                 $sql_leistung = $order_perf == 'ASC' ? "max(r.Leistung)" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, (If (r.Leistung = -98, -8,max(r.Leistung)))) * -1), max(r.Leistung))";
             } else {
                 $order2 = " rank, at.Name, at.Vorname, leistung_neu ";
                 $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, (If (r.Leistung = -98, -8,r.Leistung))) * -1), r.Leistung)";
             }
             $order = $order_heat;
             if ($ukc) {
                 if ($athleteCat) {
                     $order = $orderAthleteCat . $order_heat;
                 }
                 $selection2 = "";
                 $checkyear = date('Y') - 16;
                 $selection2 = " at.Jahrgang > {$checkyear} AND (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") AND ";
                 $query = "SELECT ss.xSerienstart, \r\n                             IF(ss.Rang=0, {$max_rank}, ss.Rang) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             IF('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)), \r\n                             at.Name, \r\n                             at.Vorname, \r\n                             at.Jahrgang, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land, \r\n                             at.xAthlet, \r\n                             ru.Datum, \r\n                             ru.Startzeit ,\r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,  \r\n                             k.Name , \r\n                             k1.Name ,                             \r\n                             k1.Anzeige ,\r\n                             ss.Bemerkung,\r\n                             w.Punkteformel,\r\n                             w.info,\r\n                             a.Startnummer,\r\n                             w.xWettkampf,\r\n                             at.Geschlecht\r\n                             \r\n                        FROM serie AS s USE INDEX(Runde)\r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN anmeldung AS a USING(xAnmeldung) \r\n                   LEFT JOIN athlet AS at USING(xAthlet) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN region AS re ON(at.xRegion = re.xRegion) \r\n                   LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie)\r\n                   LEFT JOIN kategorie AS k1 ON (a.xKategorie = k1.xKategorie)   \r\n                   LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin)   \r\n                       WHERE " . $selection2 . $roundSQL . " \r\n                       " . $limitRankSQL . " \r\n                       " . $valid_result . " \r\n                       " . $sqlSeparate . " \r\n                       " . $selectionHeats . " \r\n                     {$GroupByUkc} \r\n                    ORDER BY " . $order . $order2 . $order_perf1;
             } else {
                 if ($relay == FALSE) {
                     if ($athleteCat) {
                         $order = $orderAthleteCat . $order_heat;
                     }
                     $selection2 = "";
                     if ($ukc) {
                         $checkyear = date('Y') - 16;
                         $selection2 = " at.Jahrgang > {$checkyear} AND (d.Code = " . $cfgUKC_disc[0] . " || d.Code = " . $cfgUKC_disc[1] . " || d.Code = " . $cfgUKC_disc[2] . ") AND ";
                     }
                     if ($teamsm) {
                         $query = "SELECT ss.xSerienstart, \r\n                             IF(ss.Rang=0, {$max_rank}, ss.Rang) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             t.Name, \r\n                             at.Name, \r\n                             at.Vorname, \r\n                             at.Jahrgang, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land, \r\n                             at.xAthlet, \r\n                             ru.Datum, \r\n                             ru.Startzeit ,\r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,  \r\n                             k.Name , \r\n                             k1.Name ,                             \r\n                             k1.Anzeige ,\r\n                             ss.Bemerkung,\r\n                             w.Punkteformel,\r\n                             w.info,\r\n                             a.Startnummer,\r\n                             w.xWettkampf,\r\n                             at.Geschlecht\r\n                             \r\n                        FROM serie AS s USE INDEX(Runde)\r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN anmeldung AS a USING(xAnmeldung) \r\n                   LEFT JOIN athlet AS at USING(xAthlet) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN region AS re ON(at.xRegion = re.xRegion) \r\n                   INNER JOIN teamsmathlet AS tat ON(st.xAnmeldung = tat.xAnmeldung)\r\n                   LEFT JOIN teamsm as t ON (tat.xTeamsm = t.xTeamsm)                      \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie)\r\n                   LEFT JOIN kategorie AS k1 ON (a.xKategorie = k1.xKategorie)   \r\n                   LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin)   \r\n                       WHERE " . $selection2 . $roundSQL . " \r\n                       " . $limitRankSQL . " \r\n                       " . $valid_result . " \r\n                       " . $sqlSeparate . " \r\n                       " . $selectionHeats . " \r\n                     {$GroupByUkc} \r\n                    ORDER BY " . $order . $order2 . $order_perf;
                     } else {
                         $query = "SELECT ss.xSerienstart, \r\n                             IF(ss.Rang=0, {$max_rank}, ss.Rang) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             IF('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)), \r\n                             at.Name, \r\n                             at.Vorname, \r\n                             at.Jahrgang, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land, \r\n                             at.xAthlet, \r\n                             ru.Datum, \r\n                             ru.Startzeit ,\r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,  \r\n                             k.Name , \r\n                             k1.Name ,                             \r\n                             k1.Anzeige ,\r\n                             ss.Bemerkung,\r\n                             w.Punkteformel,\r\n                             w.info,\r\n                             a.Startnummer,\r\n                             w.xWettkampf,\r\n                             at.Geschlecht\r\n                             \r\n                        FROM serie AS s USE INDEX(Runde)\r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN anmeldung AS a USING(xAnmeldung) \r\n                   LEFT JOIN athlet AS at USING(xAthlet) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN region AS re ON(at.xRegion = re.xRegion) \r\n                   LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie)\r\n                   LEFT JOIN kategorie AS k1 ON (a.xKategorie = k1.xKategorie)   \r\n                   LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin)   \r\n                       WHERE " . $selection2 . $roundSQL . " \r\n                       " . $limitRankSQL . " \r\n                       " . $valid_result . " \r\n                       " . $sqlSeparate . " \r\n                       " . $selectionHeats . " \r\n                     {$GroupByUkc} \r\n                    ORDER BY " . $order . $order2 . $order_perf;
                     }
                 } else {
                     // relay event
                     $query = "SELECT ss.xSerienstart,                                   \r\n                             IF(r.Leistung < 0 , {$max_rank}, if (ss.Rang=0, {$max_rank}-1, ss.Rang)) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             IF('" . $svm . "', t.Name, v.Name), \r\n                             sf.Name, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             st.xStart, \r\n                             ru.Datum, \r\n                             ru.Startzeit, \r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,\r\n                             k.Name ,\r\n                             ss.Bemerkung    \r\n                        FROM serie AS s USE INDEX(Runde) \r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN staffel AS sf USING(xStaffel) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN team AS t ON(sf.xTeam = t.xTeam) \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie) \r\n                       WHERE " . $roundSQL . " \r\n                      " . $limitRankSQL . " \r\n                      " . $valid_result . " \r\n                      " . $sqlSeparate . "                         \r\n                    GROUP BY r.xSerienstart \r\n                    ORDER BY " . $order . " \r\n                             rank, \r\n                             r.Leistung \r\n                             " . $order_perf . ", \r\n                             sf.Name;";
                 }
             }
             $res = mysql_query($query);
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 if (mysql_num_rows($res) == 0) {
                     continue;
                 }
                 // initialize variables
                 $heat = '';
                 $h = 0;
                 $info = '';
                 $id = '';
                 $r = '';
                 $count_rank = 0;
                 $perf_save = '';
                 //$list->startList();
                 $nr = 0;
                 $atCat = '';
                 if ($ukc) {
                     $arr_xAthlet = array();
                     while ($row_at = mysql_fetch_array($res)) {
                         if (array_key_exists($row_at[14], $arr_xAthlet)) {
                             $arr_xAthlet[$row_at[14]]++;
                         } else {
                             $arr_xAthlet[$row_at[14]] = 1;
                         }
                     }
                 }
                 $res = mysql_query($query);
                 // process every result
                 while ($row_res = mysql_fetch_array($res)) {
                     if ($ukc) {
                         if ($arr_xAthlet[$row_res[14]] < 3) {
                             $id = $row_res[0];
                             // keep current athletes ID
                             if ($relay) {
                                 $catM = $row_res[16];
                             } else {
                                 $catM = $row_res[19];
                             }
                             // keep merged category
                             continue;
                         }
                         if ($row[0] != $row_res[18]) {
                             $id = $row_res[0];
                             // keep current athletes ID
                             if ($relay) {
                                 $catM = $row_res[16];
                             } else {
                                 $catM = $row_res[19];
                             }
                             // keep merged category
                             continue;
                         }
                         $results_ukc = TRUE;
                         $pointsUKC = AA_utils_calcPointsUKC($row_res[26], $row_res[3], 0, $row_res[27], $row_res[0]);
                         mysql_query("UPDATE resultat SET\r\n                                    Punkte = {$pointsUKC}\r\n                                WHERE\r\n                                    xSerienstart = {$row_res['0']}");
                         if (mysql_errno() > 0) {
                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                         }
                         AA_StatusChanged(0, 0, $row_res[0]);
                     }
                     if ($flagSubtitle) {
                         $r_info = '';
                         $mainRound = '';
                         if (!$teamsm) {
                             $mainRound = AA_getMainRound($row[0]);
                         }
                         if ($mainRound > 0) {
                             if ($heatSeparate) {
                                 $r_info = $roundsInfo[$row[0]];
                                 $r_info = substr($r_info, 0, -3);
                             } else {
                                 $mergedRounds = AA_getMergedRounds($row[0]);
                                 $mRounds = split(',', substr($mergedRounds, 1, -1));
                                 foreach ($mRounds as $key => $val) {
                                     $r_info .= $roundsInfo[$val];
                                 }
                                 $r_info = substr($r_info, 0, -3);
                             }
                         } else {
                             $r_info = $row_res[24];
                         }
                         $nr = 0;
                         if ($heatSeparate) {
                             if ($relay) {
                                 $list->printSubTitle($row_res[16], $row[2], $roundName, $r_info);
                             } else {
                                 if (!$athleteCat) {
                                     $list->printSubTitle($row_res[19], $row[2], $roundName, $r_info);
                                 }
                             }
                         } else {
                             if (!$athleteCat) {
                                 $list->printSubTitle($row[1], $row[2], $roundName, $r_info, $heatFrom, $heatTo, $row_rt[2]);
                             }
                         }
                         $flagSubtitle = false;
                     }
                     if (!$athleteCat) {
                         if ($flagInfoLine1) {
                             $list->printInfoLine($info_save1);
                             $flagInfoLine1 = false;
                         }
                     }
                     if (!$athleteCat) {
                         if ($flagInfoLine2) {
                             $list->printInfoLine($info_save2);
                             $flagInfoLine2 = false;
                         }
                     }
                     $row_res[3] = $row_res[3] == 1 || $row_res[3] == 2 || $row_res[3] == 3 || $row_res[3] == 4 ? $row_res[3] * -1 : ($row_res[3] == 9 ? -99 : ($row_res[3] == 8 ? -98 : $row_res[3]));
                     if ($row_res[0] != $id) {
                         if ($h == 0 || $row_res[5] != $heat && $eval == $cfgEvalType[$strEvalTypeHeat] || $athleteCat && $row_res[21] != $atCat) {
                             $count_rank = 0;
                             $nr = 0;
                             // heat name
                             if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                                 if (empty($type)) {
                                     // no round type defined
                                     $type = $strFinalround . " ";
                                 }
                                 $title = $type . $row_res[5];
                                 // heat name with nbr.
                             } else {
                                 $title = $type;
                                 // heat name withour nbr.
                             }
                             $title = trim($title);
                             // wind per heat
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeHeat]) {
                                 $heatwind = $row_res[6];
                                 // wind per heat
                             } else {
                                 $heatwind = '';
                                 // no wind
                             }
                             $wind = FALSE;
                             if ($row[8] == 1 && $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                 $wind = TRUE;
                             }
                             // add column header 'points' if required
                             $points = FALSE;
                             if ($row[7] != '0' || $row_res[23] != '0') {
                                 $points = TRUE;
                             } elseif ($ukc) {
                                 $points = TRUE;
                             }
                             if ($show_efforts == 'sb_pb') {
                                 $base_perf = true;
                             }
                             if ($athleteCat && !$relay) {
                                 if ($formaction == 'print') {
                                     if ($row_res[20] . $row[2] != $atCatName) {
                                         $list->printSubTitle($row_res[20], $row[2], $roundName, $row_res[24]);
                                         $atCatName = $row_res[20] . $row[2];
                                         if ($flagInfoLine1) {
                                             $list->printInfoLine($info_save1);
                                             $flagInfoLine1 = false;
                                         }
                                         if ($flagInfoLine2) {
                                             $list->printInfoLine($info_save2);
                                             $flagInfoLine2 = false;
                                         }
                                     }
                                 }
                             }
                             $list->startList();
                             if ($saison == "I") {
                                 $heatwind = '';
                             }
                             if ($relay && !$svm) {
                                 $points = false;
                             }
                             $list->printHeaderLine($title, $relay, $points, $wind, $heatwind, $row[11], $svm, $base_perf, $qual_mode, $eval, $withStartnr, $teamsm);
                             if ($athleteCat && !$relay) {
                                 if ($formaction == 'view') {
                                     if ($row_res[20] . $row[2] != $atCatName) {
                                         $list->printSubTitle($row_res[20], $row[2], $roundName, $row_res[24]);
                                         $atCatName = $row_res[20] . $row[2];
                                         if ($flagInfoLine1) {
                                             $list->printInfoLine($info_save1, $athleteCat);
                                             $flagInfoLine1 = false;
                                         }
                                         if ($flagInfoLine2) {
                                             $list->printInfoLine($info_save2, $athleteCat);
                                             $flagInfoLine2 = false;
                                         }
                                     }
                                 }
                             }
                             $heat = $row_res[5];
                             // keep heat description
                             $atCat = $row_res[21];
                             // keep athlete category
                             $h++;
                             // increment if evaluation per heat
                         }
                         $count_rank++;
                         // rank
                         if ($teamsm) {
                             if ($perf_save != '') {
                                 if ($perf_save == $row_res[3]) {
                                     $count_rank--;
                                     $rank = '';
                                 } else {
                                     $rank = $count_rank;
                                 }
                             } else {
                                 $rank = $count_rank;
                             }
                         } else {
                             if ($heatSeparate) {
                                 if ($row_res[1] == $max_rank || $row_res[1] == $max_rank - 1) {
                                     // invalid result
                                     $rank = '';
                                 } elseif ($r == $row_res[1] && $heat_keep == $row_res[5]) {
                                     // same rank as previous
                                     $rank = $count_rank--;
                                 } else {
                                     if ($ukc) {
                                         $rank = $count_rank;
                                     } else {
                                         $rank = $row_res[1];
                                     }
                                 }
                             } else {
                                 if ($row_res[1] == $max_rank || $row_res[1] == $max_rank - 1 || $r == $row_res[1] && $heat_keep == $row_res[5]) {
                                     // same rank as previous
                                     $rank = '';
                                 } else {
                                     if ($ukc) {
                                         $rank = $count_rank;
                                     } else {
                                         $rank = $row_res[1];
                                     }
                                 }
                             }
                         }
                         $r = $row_res[1];
                         // keep rank
                         $heat_keep = $row_res[5];
                         // keep heat
                         // name
                         $name = $row_res[9];
                         if ($relay == FALSE) {
                             $name = $name . " " . $row_res[10];
                         }
                         // year of birth
                         if ($relay == FALSE) {
                             $year = AA_formatYearOfBirth($row_res[11]);
                         } else {
                             $year = '';
                         }
                         // year of birth
                         if ($relay == FALSE) {
                             $land = $row_res[13] != '' && $row_res[13] != '-' ? $row_res[13] : '';
                         } else {
                             $year = '';
                         }
                         // performance
                         if ($row_res[3] < 0) {
                             // invalid result
                             if ($row_res[3] == '-98') {
                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow]) {
                                     $perf = $cfgInvalidResult['NRS']['short'];
                                 } else {
                                     $perf = $cfgInvalidResult['NAA']['code'];
                                 }
                             } elseif ($row_res[3] == '-99') {
                                 $perf = $cfgInvalidResult['WAI']['short'];
                             } else {
                                 foreach ($cfgInvalidResult as $value) {
                                     if ($value['code'] == $row_res[3]) {
                                         $perf = $value['short'];
                                     }
                                 }
                             }
                         } else {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                 $perf = AA_formatResultMeter($row_res[3]);
                             } else {
                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                     $perf = AA_formatResultTime($row_res[3], true, true);
                                 } else {
                                     $perf = AA_formatResultTime($row_res[3], true);
                                 }
                             }
                         }
                         $qual = '';
                         if ($row_res[2] > 0) {
                             // Athlete qualified
                             foreach ($cfgQualificationType as $qtype) {
                                 if ($qtype['code'] == $row_res[2]) {
                                     $qual = $qtype['token'];
                                 }
                             }
                         }
                         // ET athlete qualified
                         // points for performance
                         $points = '';
                         if ($row[7] != '0') {
                             $points = $row_res[7];
                         } else {
                             if ($row_res[23] != '0') {
                                 $points = $row_res[7];
                             }
                         }
                         // wind info
                         $wind = '';
                         $secondResult = false;
                         if ($r != $max_rank) {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] && $row[8] == 1) {
                                 $wind = $row_res[4];
                                 if ($saison == 'I') {
                                     $wind = '';
                                     // indoor: never wind
                                 }
                                 //
                                 // if wind bigger than max wind (2.0) show the next best result without wind too
                                 //
                                 if ($wind > 2) {
                                     $res_wind = mysql_query("\r\n                                        SELECT Info, Leistung FROM\r\n                                            resultat\r\n                                        WHERE\r\n                                            xSerienstart = {$row_res['0']}\r\n                                        ORDER BY\r\n                                            Leistung ASC");
                                     if (mysql_errno() > 0) {
                                         // DB error
                                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                     } else {
                                         while ($row_wind = mysql_fetch_array($res_wind)) {
                                             if ($row_wind[0] <= 2) {
                                                 $secondResult = true;
                                                 $wind2 = $row_wind[0] . ")";
                                                 $perf2 = "(" . AA_formatResultMeter($row_wind[1]);
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                     $wind = $row_res[6];
                                     if ($saison == 'I') {
                                         $wind = '';
                                         // indoor: never wind
                                     }
                                 }
                             }
                         }
                         // ioc country code
                         $ioc = '';
                         if ($relay == false) {
                             $ioc = $row_res[13];
                         }
                         //show performances from base
                         if ($show_efforts == 'sb_pb' && $relay == false) {
                             $sql = "SELECT \r\n                                    season_effort\r\n                                    , DATE_FORMAT(season_effort_date, '%d.%m.%Y') AS sb_date\r\n                                    , season_effort_event\r\n                                    , best_effort\r\n                                    , DATE_FORMAT(best_effort_date, '%d.%m.%Y') AS pb_date\r\n                                    , best_effort_event\r\n                                    , season\r\n                                    , xAnmeldung\r\n                        FROM \r\n                            base_performance\r\n                        LEFT JOIN \r\n                            base_athlete USING (id_athlete)\r\n                        LEFT JOIN \r\n                            disziplin_" . $_COOKIE['language'] . " ON (discipline = Code)\r\n                        LEFT JOIN \r\n                            athlet ON (license = Lizenznummer)\r\n                        LEFT JOIN\r\n                            anmeldung USING(xAthlet) \r\n                        WHERE \r\n                            athlet.xAthlet = {$row_res['14']}\r\n                            AND xDisziplin = {$row['12']}\r\n                            AND season = '{$saison}' \r\n                            AND xMeeting = " . $_COOKIE['meeting_id'] . ";";
                             $res_perf = mysql_query($sql);
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 if ($res_perf) {
                                     $row_perf = mysql_fetch_array($res_perf);
                                     $is_jump = $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh];
                                     $order = $is_jump ? 'DESC' : 'ASC';
                                     $best_previous = '';
                                     $previous_date = '';
                                     if ($row_perf !== false) {
                                         $best_previous = AA_getBestPrevious($row[12], $row_perf['xAnmeldung'], $order, $row_res['Datum'], $row_res['Startzeit'], &$previous_date);
                                     }
                                     if ($is_jump) {
                                         $sb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['season_effort']));
                                         $pb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['best_effort']));
                                         $bp_perf = AA_formatResultMeter(str_replace(".", "", $best_previous));
                                         if ($bp_perf > 0 && $bp_perf > $sb_perf) {
                                             $sb_perf = $bp_perf;
                                             $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($bp_perf > 0 && $bp_perf > $pb_perf) {
                                             $pb_perf = $bp_perf;
                                             $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         //highlight sb or pb if new performance is better
                                         if (is_numeric($perf)) {
                                             //prevent special-codes (disq, n.a. usw)
                                             if ($formaction != 'print') {
                                                 if ($pb_perf != '' && $perf > $pb_perf) {
                                                     $perf = "<b>PB {$perf}</b> ";
                                                 } else {
                                                     if ($sb_perf != '' && $perf > $sb_perf) {
                                                         $perf = "<b>SB {$perf}</b>";
                                                     }
                                                 }
                                             } else {
                                                 if ($pb_perf != '' && $perf > $pb_perf) {
                                                     $perf = "<b>PB</b> {$perf}";
                                                 } else {
                                                     if ($sb_perf != '' && $perf > $sb_perf) {
                                                         $perf = "<b>SB</b> {$perf}";
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         //convert performance-time to milliseconds
                                         $timepices = explode(":", $row_perf['season_effort']);
                                         $season_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                         $timepices = explode(":", $row_perf['best_effort']);
                                         $best_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                         $previous_effort = intval($best_previous);
                                         if ($previous_effort > 0 && $previous_effort < $season_effort) {
                                             $season_effort = $previous_effort;
                                             $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($previous_effort > 0 && $previous_effort < $best_effort) {
                                             $best_effort = $previous_effort;
                                             $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                             $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                         }
                                         if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                             $sb_perf = AA_formatResultTime($season_effort, true, true);
                                             $pb_perf = AA_formatResultTime($best_effort, true, true);
                                         } else {
                                             $sb_perf = AA_formatResultTime($season_effort, true);
                                             $pb_perf = AA_formatResultTime($best_effort, true);
                                         }
                                         if ($formaction != 'print') {
                                             //highlight sb or pb if new performance is better
                                             if ($pb_perf != '' && $perf < $pb_perf) {
                                                 $perf = "<b>PB {$perf}</b>";
                                             } else {
                                                 if ($sb_perf != '' && $perf < $sb_perf) {
                                                     $perf = "<b>SB {$perf}</b>";
                                                 }
                                             }
                                         } else {
                                             if ($pb_perf != '' && $perf < $pb_perf) {
                                                 $perf = "<b>PB</b> {$perf}";
                                             } else {
                                                 if ($sb_perf != '' && $perf < $sb_perf) {
                                                     $perf = "<b>SB</b> {$perf}";
                                                 }
                                             }
                                         }
                                     }
                                     if (!empty($row_perf['season_effort'])) {
                                         $sb = "<a href=\"#\" class=\"info\">{$sb_perf}<span>{$row_perf['sb_date']}<br>{$row_perf['season_effort_event']}</span></a>";
                                     } else {
                                         $sb = "&nbsp;";
                                     }
                                     if (!empty($row_perf['best_effort'])) {
                                         $pb = "<a href=\"#\" class=\"info\">{$pb_perf}<span>{$row_perf['pb_date']}<br>{$row_perf['best_effort_event']}</span></a>";
                                     } else {
                                         $pb = "&nbsp;";
                                     }
                                 }
                             }
                         }
                         if ($heatSeparate && $row_res[17] > 0) {
                             $rank = $count_rank;
                             if ($row_res[3] < 0) {
                                 // invalid result
                                 $rank = '';
                             }
                         }
                         if ($athleteCat && !$relay) {
                             $nr++;
                             if ($rank != '') {
                                 if ($formaction == "print") {
                                     $rank = $nr . ". (" . $rank . ")";
                                 } else {
                                     $rank = $nr . " (" . $rank . ")";
                                 }
                             }
                         } else {
                             if ($formaction == "print") {
                                 if ($rank != '') {
                                     $rank .= ".";
                                 }
                             }
                         }
                         if ($relay) {
                             $remark = $row_res[17];
                         } else {
                             $remark = $row_res[22];
                         }
                         if ($wind == '-' && $perf == 0) {
                             $wind = '';
                         }
                         if ($ukc) {
                             $points = $pointsUKC;
                         }
                         $list->printLine($rank, $name, $year, $row_res[8], $perf, $wind, $points, $qual, $ioc, $sb, $pb, $qual_mode, $athleteCat, $remark, '', $withStartnr, $row_res[25]);
                         if ($secondResult) {
                             $list->printLine("", "", "", "", $perf2, $wind2, "", "", "", "", "", $qual_mode, "", "", $secondResult);
                         }
                         $perf_save = $row_res[3];
                         // keep performance
                         //
                         // if relay, show started ahtletes in right order under the result
                         //
                         if ($relay) {
                             if ($row_res[14] > 0) {
                                 $sqlRound = $row_res[14];
                             } else {
                                 $sqlRound = $row[0];
                             }
                             $res_at = mysql_query("\r\n                                SELECT at.Vorname, at.Name, at.Jahrgang FROM\r\n                                    staffelathlet as sfat\r\n                                    LEFT JOIN start as st ON sfat.xAthletenstart = st.xStart\r\n                                    LEFT JOIN anmeldung as a USING(xAnmeldung)\r\n                                    LEFT JOIN athlet as at USING(xAthlet)\r\n                                WHERE\r\n                                    sfat.xStaffelstart = {$row_res['11']}\r\n                                AND    sfat.xRunde = {$sqlRound} \r\n                                ORDER BY\r\n                                    sfat.Position\r\n                                LIMIT {$row['10']}\r\n                        ");
                             if (mysql_errno() > 0) {
                                 // DB error
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 $text_at = "";
                                 while ($row_at = mysql_fetch_array($res_at)) {
                                     $text_at .= $row_at[1] . " " . $row_at[0] . " " . AA_formatYearOfBirth($row_at[2]) . " / ";
                                 }
                                 $text_at = substr($text_at, 0, strlen($text_at) - 2);
                                 $text_at = trim($text_at) != '' ? '(' . $text_at . ')' : '';
                                 $list->printAthletesLine($text_at);
                             }
                         }
                         //
                         // if biglist, show all attempts
                         //
                         if ($biglist) {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                 $query_sort = $row[3] == $cfgDisciplineType[$strDiscTypeHigh] ? "ORDER BY Leistung ASC" : "";
                                 $res_att = mysql_query("\r\n                                SELECT * FROM \r\n                                    resultat \r\n                                WHERE xSerienstart = {$row_res['0']}\r\n                                " . $query_sort . "\r\n                                ");
                                 if (mysql_errno() > 0) {
                                     // DB error
                                     AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                 } else {
                                     $text_att = "";
                                     while ($row_att = mysql_fetch_array($res_att)) {
                                         if ($row_att['Leistung'] < 0) {
                                             $perf3 = $row_att['Leistung'];
                                             if ($perf3 == $GLOBALS['cfgMissedAttempt']['db']) {
                                                 // $perf3 = '-';
                                                 $perf3 = $GLOBALS['cfgMissedAttempt']['code'];
                                             } elseif ($perf3 == $GLOBALS['cfgMissedAttempt']['dbx']) {
                                                 $perf3 = $GLOBALS['cfgMissedAttempt']['codeX'];
                                             }
                                             foreach ($cfgInvalidResult as $value) {
                                                 if ($value['code'] == $perf3) {
                                                     $text_att .= $value['short'];
                                                 }
                                             }
                                             $text_att .= " / ";
                                         } else {
                                             $text_att .= $row_att['Leistung'] == '-' ? '-' : AA_formatResultMeter($row_att['Leistung']);
                                             if ($saison == "O" || $saison == "I" && $row[3] != $cfgDisciplineType[$strDiscTypeJump]) {
                                                 // outdoor  or (indoor and not jump)
                                                 if ($row_att['Info'] != "-" && !empty($row_att['Info']) && $row[3] != $cfgDisciplineType[$strDiscTypeThrow]) {
                                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                                         $text_att .= " , " . $row_att['Info'];
                                                     } else {
                                                         if ($row[8] != 0) {
                                                             $text_att .= " , " . $row_att['Info'];
                                                         }
                                                     }
                                                 } elseif ($row_att['Info'] == "-" && $row[3] != $cfgDisciplineType[$strDiscTypeThrow] && $row_att['Leistung'] > 0) {
                                                     $text_att .= " , " . $row_att['Info'];
                                                 }
                                             }
                                             $text_att .= " / ";
                                         }
                                     }
                                     $text_att = substr($text_att, 0, strlen($text_att) - 2);
                                     $list->printAthletesLine("{$strAttempts}: ( {$text_att} )");
                                 }
                             }
                         }
                     }
                     // ET athlete processed
                     $id = $row_res[0];
                     // keep current athletes ID
                     if ($relay) {
                         $catM = $row_res[16];
                     } else {
                         $catM = $row_res[19];
                     }
                     // keep merged category
                 }
                 // END WHILE result lines
                 mysql_free_result($res);
                 $list->endList();
             }
             // ET DB error result rows
             $cat = $row[1];
             // keep category
             $round_keep = $row[0];
         }
         // END WHILE event rounds
         mysql_free_result($results);
         if ($ukc && !$results_ukc) {
             echo "<br><br><b><blockquote>{$strErrNoResults}</blockquote></b>";
         }
         //************** rankinglist over all series
         if ($ranklistAll) {
             if ($catMerged & !$heatSeparate || $eventMerged & !$heatSeparate) {
                 // get event rounds from DB
                 $results = mysql_query("\r\n                        SELECT \r\n                            r.xRunde\r\n                            , k.Name\r\n                            , d.Name\r\n                            , d.Typ\r\n                            , w.xWettkampf\r\n                            , r.QualifikationSieger\r\n                            , r.QualifikationLeistung\r\n                            , w.Punkteformel\r\n                            , w.Windmessung\r\n                            , r.Speakerstatus\r\n                            , d.Staffellaeufer\r\n                            , CONCAT(DATE_FORMAT(r.Datum,'{$cfgDBdateFormat}'), ' ', TIME_FORMAT(r.Startzeit, '{$cfgDBtimeFormat}'))\r\n                            , w.xDisziplin  \r\n                        FROM\r\n                            wettkampf AS w\r\n                            LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie)\r\n                              LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                              LEFT JOIN runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n                        WHERE " . $selection . "\r\n                        w.xMeeting = " . $_COOKIE['meeting_id'] . "     \r\n                        AND r.Status = " . $cfgRoundStatus['results_done'] . " \r\n                        AND r.Datum LIKE '" . $date . "'\r\n                        AND (d.Typ = " . $cfgDisciplineType[$strDiscTypeTrack] . " OR d.Typ = " . $cfgDisciplineType[$strDiscTypeTrackNoWind] . " \r\n                                OR d.Typ = " . $cfgDisciplineType[$strDiscTypeRelay] . " OR d.Typ = " . $cfgDisciplineType[$strDiscTypeDistance] . ")             \r\n                        ORDER BY\r\n                            k.Anzeige\r\n                            , d.Anzeige\r\n                            , r.Datum\r\n                            , r.Startzeit\r\n                    ");
             } else {
                 // heats separate
                 $results = mysql_query("\r\n                            SELECT DISTINCT \r\n                                r.xRunde , \r\n                                k.Name , \r\n                                d.Name , \r\n                                d.Typ , \r\n                                w.xWettkampf , \r\n                                r.QualifikationSieger , \r\n                                r.QualifikationLeistung , \r\n                                w.Punkteformel , \r\n                                w.Windmessung , \r\n                                r.Speakerstatus , \r\n                                d.Staffellaeufer , \r\n                                CONCAT(DATE_FORMAT(r.Datum,'%d.%m.%y'), \r\n                                ' ', \r\n                                TIME_FORMAT(r.Startzeit, '%H:%i')) ,\r\n                                w.xDisziplin ,  \r\n                                rs.Hauptrunde     \r\n                            FROM \r\n                                wettkampf AS w \r\n                                LEFT JOIN kategorie AS k ON (k.xKategorie = w.xKategorie) \r\n                                LEFT JOIN disziplin_" . $_COOKIE['language'] . " as d ON (d.xDisziplin = w.xDisziplin) \r\n                                LEFT JOIN runde AS r ON (r.xWettkampf = w.xWettkampf) \r\n                                LEFT JOIN rundenset as rs ON (r.xRunde=rs.xRunde )           \r\n                            WHERE \r\n                                " . $selection . "  \r\n                                w.xMeeting  = " . $_COOKIE['meeting_id'] . " \r\n                                AND r.Status = 4  \r\n                                AND r.Datum LIKE '%' \r\n                            ORDER BY\r\n                                k.Anzeige\r\n                                , d.Anzeige\r\n                                , r.Datum\r\n                                , r.Startzeit\r\n                ");
             }
             if (mysql_errno() > 0) {
                 // DB error
                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
             } else {
                 $limitRankSQL = "";
                 $limitRank = false;
                 if ($_GET['limitRank'] == "yes") {
                     // check if ranks are limited, but limitRankSQL will set only if export is pressed
                     if (!empty($_GET['limitRankFrom']) && !empty($_GET['limitRankTo'])) {
                         $limitRank = true;
                     }
                 }
                 // start a new HTML display page
                 if ($formaction == 'view' || $formaction == 'speaker') {
                     // display page
                     $list->printPageTitle("{$strRanklistAll} " . $_COOKIE['meeting']);
                 } elseif ($formaction == "print") {
                     $list->insertPageBreak();
                     $list->printPageTitle("{$strRanklistAll}");
                 }
                 // initialize variables
                 $cat = '';
                 $evnt = 0;
                 if (mysql_num_rows($results) == 0) {
                     echo "<br><br><b><blockquote>{$strErrNoResults}</blockquote></b>";
                 }
                 while ($row = mysql_fetch_row($results)) {
                     // for a combined event, the rounds are merged, so jump until the next event
                     if ($cRounds > 1) {
                         $cRounds--;
                         continue;
                     }
                     $roundSQL = "s.xRunde = {$row['0']}";
                     $cRounds = 0;
                     // check page  break
                     if (is_a($list, "PRINT_RankingList") && $cat != '' && ($break == 'discipline' || $break == 'category' && $row[1] != $cat)) {
                         $list->insertPageBreak();
                     }
                     if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeRelay]) {
                         $eval = $cfgEvalType[$strEvalTypeHeat];
                     } else {
                         $eval = $cfgEvalType[$strEvalTypeAll];
                     }
                     $roundName = '';
                     $type = '';
                     $res = mysql_query("\r\n            SELECT\r\n                rt.Name\r\n                , rt.Typ\r\n                , rt.Wertung\r\n            FROM\r\n                runde\r\n                LEFT JOIN rundentyp_" . $_COOKIE['language'] . " AS rt ON (rt.xRundentyp = runde.xRundentyp)\r\n            WHERE \r\n                runde.xRunde = {$row['0']}");
                     if (mysql_errno() > 0) {
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         if (mysql_num_rows($res) > 0) {
                             $row_rt = mysql_fetch_row($res);
                             if ($row_rt[1] == '0') {
                                 $type = " ";
                                 $row_rt[0] = '';
                             } else {
                                 $type = $row_rt[0] . " ";
                             }
                             $eval = $row_rt[2];
                             if ($round != 0) {
                                 // specific round selected
                                 $roundName = $row_rt[0];
                             }
                         }
                         mysql_free_result($res);
                     }
                     $flagSubtitle = false;
                     // set flag to print the subtitle later
                     if ($evnt != $row[4]) {
                         // if this is a combined event, dont fragment list by rounds
                         $combined = AA_checkCombined($row[4]);
                         // not selectet a specific round
                         if ($round == 0 && $combined) {
                             $sql = "SELECT \r\n                                r.xRunde\r\n                            FROM\r\n                                wettkampf as w\r\n                                LEFT JOIN runde as r ON (r.xWettkampf = w.xWettkampf)\r\n                            WHERE    \r\n                                w.xWettkampf = {$row['4']}\r\n                                AND r.status = 4";
                             $res_c = mysql_query($sql);
                             if (mysql_errno() > 0) {
                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                             } else {
                                 $cRounds = mysql_num_rows($res_c);
                                 $roundSQL = "s.xRunde IN (";
                                 while ($row_c = mysql_fetch_array($res_c)) {
                                     $roundSQL .= $row_c[0] . ",";
                                 }
                                 $roundSQL = substr($roundSQL, 0, -1) . ")";
                             }
                         }
                         // set up category and discipline title information
                         $flagSubtitle = true;
                         // set flag to print the subtitle later
                         if ($formaction == 'speaker' && AA_getNextRound($row[4], $row[0]) == 0) {
                             // last round: show ceremony status
                             $list->printCeremonyStatus($row[0], $row[9]);
                         }
                         // print qualification mode if round selected
                         $info = '';
                         if ($round > 0 && ($row[5] > 0 || $row[6] > 0)) {
                             $info = "{$strQualification}: " . $row[5] . " {$strQualifyTop}, " . $row[6] . " {$strQualifyPerformance}";
                             $flagInfoLine1 = true;
                             // set flag to print later the qualification mode if round selected
                             $info_save1 = $info;
                             //$list->printInfoLine($info);
                             $qual_mode = TRUE;
                         }
                         // print qualification descriptions if required
                         $info = '';
                         if ($row[5] > 0 || $row[6] > 0) {
                             foreach ($cfgQualificationType as $qt) {
                                 $info = $info . $qt['token'] . " =" . $qt['text'] . "&nbsp;&nbsp;&nbsp;";
                             }
                             $flagInfoLine2 = true;
                             // set flag to print later the qualification descriptions if required
                             $info_save2 = $info;
                             //$list->printInfoLine($info);
                             $qual_mode = TRUE;
                         }
                         $evnt = $row[4];
                         // keep event ID
                     }
                     // ET new event
                     $relay = AA_checkRelay($row[4]);
                     // check, if this is a relay event
                     $svm = AA_checkSVM($row[4]);
                     // If round evaluated per heat, group results accordingly
                     $order_heat = "";
                     if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                         // eval per heat
                         $order_heat = "heatid, ";
                     }
                     $valid_result = "";
                     // Order performance depending on discipline type
                     if ($row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow]) {
                         $order_perf = "DESC";
                     } else {
                         if ($row[3] == $cfgDisciplineType[$strDiscTypeJump]) {
                             if ($row[8] == 1) {
                                 // with wind
                                 $order_perf = "DESC, r.Info ASC";
                             } else {
                                 // without wind
                                 $order_perf = "DESC";
                             }
                         } else {
                             if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                 $order_perf = "DESC";
                                 $valid_result = " AND (r.Info LIKE '%O%'" . " OR r.Leistung < 0)";
                             } else {
                                 $order_perf = "ASC";
                             }
                         }
                     }
                     $sqlSeparate = '';
                     if (($catMerged || $eventMerged) & $heatSeparate) {
                         if ($row[0] > 0 && $row[13] != NULL) {
                             $roundSQL = '';
                             if (empty($limitRankSQL) && empty($valid_result)) {
                                 $sqlSeparate = " ss.RundeZusammen = " . $row[0];
                             } else {
                                 if (empty($limitRankSQL)) {
                                     $valid_result = substr($valid_result, 4, strlen($valid_result));
                                 } elseif (empty($valid_result)) {
                                     $limitRankSQL = substr($limitRankSQL, 4, strlen($limitRankSQL));
                                 }
                                 $sqlSeparate = " AND ss.RundeZusammen = " . $row[0];
                             }
                         }
                     }
                     // get all results ordered by ranking; for invalid results (Rang=0), the
                     // rank is set to max_rank to put them to the end of the list.
                     $max_rank = 999999999;
                     $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, (If (r.Leistung = -98, -8,r.Leistung))) * -1), r.Leistung)";
                     $sql_leistung_order = "IF(r.Leistung is NULL, 999999999  , (IF (r.Leistung < 0,999999999 - r.Leistung,  r.Leistung )))";
                     $order = $order_heat;
                     if ($relay == FALSE) {
                         if ($athleteCat) {
                             $order = $orderAthleteCat . $order_heat;
                         }
                         $query = "SELECT ss.xSerienstart, \r\n                             IF(ss.Rang=0, {$max_rank}, ss.Rang) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             IF('" . $svm . "', t.Name, IF(a.Vereinsinfo = '', v.Name, a.Vereinsinfo)), \r\n                             at.Name, \r\n                             at.Vorname, \r\n                             at.Jahrgang, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             IF(at.xRegion = 0, at.Land, re.Anzeige) AS Land, \r\n                             at.xAthlet, \r\n                             ru.Datum, \r\n                             ru.Startzeit ,\r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,  \r\n                             k.Name , \r\n                             k1.Name ,                             \r\n                             k1.Anzeige ,\r\n                             ss.Bemerkung,\r\n                             w.Punkteformel,\r\n                             w.info,\r\n                             a.Startnummer,\r\n                             " . $sql_leistung_order . " AS leistung_order, \r\n                             r.Leistung\r\n                        FROM serie AS s USE INDEX(Runde)\r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN anmeldung AS a USING(xAnmeldung) \r\n                   LEFT JOIN athlet AS at USING(xAthlet) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN region AS re ON(at.xRegion = re.xRegion) \r\n                   LEFT JOIN team AS t ON(a.xTeam = t.xTeam) \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie)\r\n                   LEFT JOIN kategorie AS k1 ON (a.xKategorie = k1.xKategorie)   \r\n                       WHERE " . $roundSQL . " \r\n                       " . $limitRankSQL . " \r\n                       " . $valid_result . " \r\n                       " . $sqlSeparate . " \r\n                       " . $selectionHeats . "  \r\n                    ORDER BY leistung_order " . $order_perf;
                     } else {
                         // relay event
                         $query = "SELECT ss.xSerienstart,                                   \r\n                             IF(r.Leistung < 0 , {$max_rank}, if (ss.Rang=0, {$max_rank}-1, ss.Rang)) AS rank, \r\n                             ss.Qualifikation, \r\n                             " . $sql_leistung . " AS leistung_neu, \r\n                             r.Info, \r\n                             s.Bezeichnung, \r\n                             s.Wind, \r\n                             r.Punkte, \r\n                             IF('" . $svm . "', t.Name, v.Name), \r\n                             sf.Name, \r\n                             LPAD(s.Bezeichnung, 5, '0') AS heatid, \r\n                             st.xStart, \r\n                             ru.Datum, \r\n                             ru.Startzeit, \r\n                             ss.RundeZusammen,\r\n                             ru.xRunde,\r\n                             k.Name ,\r\n                             ss.Bemerkung    \r\n                        FROM serie AS s USE INDEX(Runde) \r\n                   LEFT JOIN serienstart AS ss USING(xSerie) \r\n                   LEFT JOIN resultat AS r USING(xSerienstart) \r\n                   LEFT JOIN start AS st ON(ss.xStart = st.xStart) \r\n                   LEFT JOIN staffel AS sf USING(xStaffel) \r\n                   LEFT JOIN verein AS v USING(xVerein) \r\n                   LEFT JOIN team AS t ON(sf.xTeam = t.xTeam) \r\n                   LEFT JOIN runde AS ru ON(s.xRunde = ru.xRunde) \r\n                   LEFT JOIN wettkampf AS w On (w.xWettkampf= st.xWettkampf)   \r\n                   LEFT JOIN kategorie AS k On (w.xKategorie= k.xKategorie) \r\n                       WHERE " . $roundSQL . " \r\n                      " . $limitRankSQL . " \r\n                      " . $valid_result . " \r\n                      " . $sqlSeparate . "                         \r\n                    GROUP BY r.xSerienstart \r\n                    ORDER BY " . $order . " \r\n                             rank, \r\n                             r.Leistung \r\n                             " . $order_perf . ", \r\n                             sf.Name;";
                     }
                     $res = mysql_query($query);
                     if (mysql_errno() > 0) {
                         // DB error
                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                     } else {
                         if (mysql_num_rows($res) == 0) {
                             continue;
                         }
                         // initialize variables
                         $heat = '';
                         $h = 0;
                         $info = '';
                         $id = '';
                         $r = '';
                         $count_rank = 0;
                         $perf_save = '';
                         $nr = 0;
                         if ($formaction == 'view') {
                             $list->startList();
                         }
                         $atCat = '';
                         // process every result
                         while ($row_res = mysql_fetch_array($res)) {
                             if ($flagSubtitle) {
                                 $nr = 0;
                                 if ($heatSeparate) {
                                     if ($relay) {
                                         $list->printSubTitle($row_res[16], $row2_keep, $roundName, $row_res[24]);
                                     } else {
                                         if (!$athleteCat) {
                                             $list->printSubTitle($row_res[19], $row2_keep, $roundName, $row_res[24]);
                                         }
                                     }
                                 } else {
                                     if (!$athleteCat) {
                                         if ($formaction == 'print') {
                                             $list->printSubTitle($row[1], $row[2], $roundName, $row_res[24]);
                                         } else {
                                             $list->printSubTitle($row[1], $row[2], $roundName, $row_res[24]);
                                         }
                                     }
                                 }
                                 $flagSubtitle = false;
                                 if ($formaction == 'print') {
                                     $list->startList();
                                 }
                             }
                             /*
                                 if (!$athleteCat){ 
                                     if ($flagInfoLine1){   
                                         $list->printInfoLine($info_save1);
                                         $flagInfoLine1=false;  
                                     }
                                 }
                                 if (!$athleteCat){ 
                                      if ($flagInfoLine2){  
                                         $list->printInfoLine($info_save2);
                                         $flagInfoLine2=false;  
                                     }
                                 } 
                             */
                             $row_res[3] = $row_res[3] == 1 || $row_res[3] == 2 || $row_res[3] == 3 || $row_res[3] == 4 ? $row_res[3] * -1 : ($row_res[3] == 9 ? -99 : ($row_res[3] == 8 ? -98 : $row_res[3]));
                             $nr = 0;
                             $title = trim($title);
                             if ($row_res[0] != $id) {
                                 if ($h == 0) {
                                     $count_rank = 0;
                                     $nr = 0;
                                     // heat name
                                     if ($eval == $cfgEvalType[$strEvalTypeHeat]) {
                                         if (empty($type)) {
                                             // no round type defined
                                             $type = $strFinalround . " ";
                                         }
                                         $title = $type;
                                         // heat name withour nbr.
                                     } else {
                                         $title = $type;
                                         // heat name withour nbr.
                                     }
                                     $title = trim($title);
                                     // wind per heat
                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeHeat]) {
                                         $heatwind = $row_res[6];
                                         // wind per heat
                                     } else {
                                         $heatwind = '';
                                         // no wind
                                     }
                                     $wind = FALSE;
                                     if ($row[8] == 1 && $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                         $wind = TRUE;
                                     }
                                     // add column header 'points' if required
                                     $points = FALSE;
                                     if ($row[7] != '0' || $row_res[23] != '0') {
                                         $points = TRUE;
                                     }
                                     if ($show_efforts == 'sb_pb') {
                                         $base_perf = true;
                                     }
                                     if ($athleteCat && !$relay) {
                                         if ($formaction == 'print') {
                                             if ($row_res[20] . $row[2] != $atCatName) {
                                                 $list->printSubTitle($row_res[20], $row2_keep, $roundName, $row_res[24]);
                                                 $atCatName = $row_res[20] . $row[2];
                                                 if ($flagInfoLine1) {
                                                     $list->printInfoLine($info_save1);
                                                     $flagInfoLine1 = false;
                                                 }
                                                 if ($flagInfoLine2) {
                                                     $list->printInfoLine($info_save2);
                                                     $flagInfoLine2 = false;
                                                 }
                                             }
                                         }
                                     }
                                     //  $list->startList();
                                     if ($saison == "I") {
                                         $heatwind = '';
                                     }
                                     $list->printHeaderLine($title, $relay, $points, $wind, $heatwind, $row[11], $svm, $base_perf, $qual_mode, $eval, $withStartnr);
                                     if ($athleteCat && !$relay) {
                                         if ($formaction == 'view') {
                                             if ($row_res[20] . $row[2] != $atCatName) {
                                                 $list->printSubTitle($row_res[20], $row[2], $roundName, $row_res[24]);
                                                 $atCatName = $row_res[20] . $row[2];
                                                 if ($flagInfoLine1) {
                                                     $list->printInfoLine($info_save1, $athleteCat);
                                                     $flagInfoLine1 = false;
                                                 }
                                                 if ($flagInfoLine2) {
                                                     $list->printInfoLine($info_save2, $athleteCat);
                                                     $flagInfoLine2 = false;
                                                 }
                                             }
                                         }
                                     }
                                     $heat = $row_res[5];
                                     // keep heat description
                                     $atCat = $row_res[21];
                                     // keep athlete category
                                     $h++;
                                     // increment if evaluation per heat
                                 }
                                 $count_rank++;
                                 // rank
                                 if ($row_res[1] == $max_rank || $row_res[1] == $max_rank - 1 || $r == $row_res[1] && $heat_keep == $row_res[5]) {
                                     // same rank as previous
                                     $rank = '';
                                 } else {
                                     $rank = $row_res[1];
                                 }
                                 $r = $row_res[1];
                                 // keep rank
                                 $heat_keep = $row_res[5];
                                 // keep rank
                                 // name
                                 $name = $row_res[9];
                                 if ($relay == FALSE) {
                                     $name = $name . " " . $row_res[10];
                                 }
                                 // year of birth
                                 if ($relay == FALSE) {
                                     $year = AA_formatYearOfBirth($row_res[11]);
                                 } else {
                                     $year = '';
                                 }
                                 // year of birth
                                 if ($relay == FALSE) {
                                     $land = $row_res[13] != '' && $row_res[13] != '-' ? $row_res[13] : '';
                                 } else {
                                     $year = '';
                                 }
                                 // performance
                                 if ($row_res[3] < 0) {
                                     // invalid result
                                     if ($row_res[3] == '-98') {
                                         $perf = $cfgInvalidResult['NAA']['code'];
                                     } elseif ($row_res[3] == '-99') {
                                         $perf = $cfgInvalidResult['WAI']['short'];
                                     } else {
                                         foreach ($cfgInvalidResult as $value) {
                                             if ($value['code'] == $row_res[3]) {
                                                 $perf = $value['short'];
                                             }
                                         }
                                     }
                                 } else {
                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                         $perf = AA_formatResultMeter($row_res[3]);
                                     } else {
                                         if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                             $perf = AA_formatResultTime($row_res[3], true, true);
                                         } else {
                                             $perf = AA_formatResultTime($row_res[3], true);
                                         }
                                     }
                                 }
                                 $qual = '';
                                 if ($row_res[2] > 0) {
                                     // Athlete qualified
                                     foreach ($cfgQualificationType as $qtype) {
                                         if ($qtype['code'] == $row_res[2]) {
                                             $qual = $qtype['token'];
                                         }
                                     }
                                 }
                                 // ET athlete qualified
                                 // points for performance
                                 $points = '';
                                 if ($row[7] != '0') {
                                     $points = $row_res[7];
                                 } else {
                                     if ($row_res[23] != '0') {
                                         $points = $row_res[7];
                                     }
                                 }
                                 // wind info
                                 $wind = '';
                                 $secondResult = false;
                                 if ($r != $max_rank) {
                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] && $row[8] == 1) {
                                         $wind = $row_res[4];
                                         if ($saison == 'I') {
                                             $wind = '';
                                             // indoor: never wind
                                         }
                                         //
                                         // if wind bigger than max wind (2.0) show the next best result without wind too
                                         //
                                         if ($wind > 2) {
                                             $res_wind = mysql_query("\r\n                                        SELECT Info, Leistung FROM\r\n                                            resultat\r\n                                        WHERE\r\n                                            xSerienstart = {$row_res['0']}\r\n                                        ORDER BY\r\n                                            Leistung ASC");
                                             if (mysql_errno() > 0) {
                                                 // DB error
                                                 AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                             } else {
                                                 while ($row_wind = mysql_fetch_array($res_wind)) {
                                                     if ($row_wind[0] <= 2) {
                                                         $secondResult = true;
                                                         $wind2 = $row_wind[0] . ")";
                                                         $perf2 = "(" . AA_formatResultMeter($row_wind[1]);
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] && $row[8] == 1 && $eval == $cfgEvalType[$strEvalTypeAll]) {
                                             $wind = $row_res[6];
                                             if ($saison == 'I') {
                                                 $wind = '';
                                                 // indoor: never wind
                                             }
                                         }
                                     }
                                 }
                                 // ioc country code
                                 $ioc = '';
                                 if ($relay == false) {
                                     $ioc = $row_res[13];
                                 }
                                 //show performances from base
                                 if ($show_efforts == 'sb_pb' && $relay == false) {
                                     $sql = "SELECT \r\n                                    season_effort\r\n                                    , DATE_FORMAT(season_effort_date, '%d.%m.%Y') AS sb_date\r\n                                    , season_effort_event\r\n                                    , best_effort\r\n                                    , DATE_FORMAT(best_effort_date, '%d.%m.%Y') AS pb_date\r\n                                    , best_effort_event\r\n                                    , season\r\n                                    , xAnmeldung\r\n                        FROM \r\n                            base_performance\r\n                        LEFT JOIN \r\n                            base_athlete USING (id_athlete)\r\n                        LEFT JOIN \r\n                            disziplin_" . $_COOKIE['language'] . " ON (discipline = Code)\r\n                        LEFT JOIN \r\n                            athlet ON (license = Lizenznummer)\r\n                        LEFT JOIN\r\n                            anmeldung USING(xAthlet) \r\n                        WHERE \r\n                            athlet.xAthlet = {$row_res['14']}\r\n                            AND xDisziplin = {$row['12']}\r\n                            AND season = '{$saison}' \r\n                            AND xMeeting = " . $_COOKIE['meeting_id'] . ";";
                                     $res_perf = mysql_query($sql);
                                     if (mysql_errno() > 0) {
                                         // DB error
                                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                     } else {
                                         if ($res_perf) {
                                             $row_perf = mysql_fetch_array($res_perf);
                                             $is_jump = $row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh];
                                             $order = $is_jump ? 'DESC' : 'ASC';
                                             $best_previous = '';
                                             $previous_date = '';
                                             if ($row_perf !== false) {
                                                 $best_previous = AA_getBestPrevious($row[12], $row_perf['xAnmeldung'], $order, $row_res['Datum'], $row_res['Startzeit'], &$previous_date);
                                             }
                                             if ($is_jump) {
                                                 $sb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['season_effort']));
                                                 $pb_perf = AA_formatResultMeter(str_replace(".", "", $row_perf['best_effort']));
                                                 $bp_perf = AA_formatResultMeter(str_replace(".", "", $best_previous));
                                                 if ($bp_perf > 0 && $bp_perf > $sb_perf) {
                                                     $sb_perf = $bp_perf;
                                                     $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                                     $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                                 }
                                                 if ($bp_perf > 0 && $bp_perf > $pb_perf) {
                                                     $pb_perf = $bp_perf;
                                                     $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                                     $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                                 }
                                                 //highlight sb or pb if new performance is better
                                                 if (is_numeric($perf)) {
                                                     //prevent special-codes (disq, n.a. usw)
                                                     if ($formaction != 'print') {
                                                         if ($pb_perf != '' && $perf > $pb_perf) {
                                                             $perf = "<b>PB {$perf}</b> ";
                                                         } else {
                                                             if ($sb_perf != '' && $perf > $sb_perf) {
                                                                 $perf = "<b>SB {$perf}</b>";
                                                             }
                                                         }
                                                     } else {
                                                         if ($pb_perf != '' && $perf > $pb_perf) {
                                                             $perf = "<b>PB</b> {$perf}";
                                                         } else {
                                                             if ($sb_perf != '' && $perf > $sb_perf) {
                                                                 $perf = "<b>SB</b> {$perf}";
                                                             }
                                                         }
                                                     }
                                                 }
                                             } else {
                                                 //convert performance-time to milliseconds
                                                 $timepices = explode(":", $row_perf['season_effort']);
                                                 $season_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                                 $timepices = explode(":", $row_perf['best_effort']);
                                                 $best_effort = $timepices[0] * 360 * 1000 + $timepices[1] * 60 * 1000 + $timepices[2] * 1000 + $timepices[3];
                                                 $previous_effort = intval($best_previous);
                                                 if ($previous_effort > 0 && $previous_effort < $season_effort) {
                                                     $season_effort = $previous_effort;
                                                     $row_perf['season_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                                     $row_perf['sb_date'] = date('d.m.Y', strtotime($previous_date));
                                                 }
                                                 if ($previous_effort > 0 && $previous_effort < $best_effort) {
                                                     $best_effort = $previous_effort;
                                                     $row_perf['best_effort_event'] = $_SESSION['meeting_infos']['Name'];
                                                     $row_perf['pb_date'] = date('d.m.Y', strtotime($previous_date));
                                                 }
                                                 if ($row[3] == $cfgDisciplineType[$strDiscTypeTrack] || $row[3] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                                                     $sb_perf = AA_formatResultTime($season_effort, true, true);
                                                     $pb_perf = AA_formatResultTime($best_effort, true, true);
                                                 } else {
                                                     $sb_perf = AA_formatResultTime($season_effort, true);
                                                     $pb_perf = AA_formatResultTime($best_effort, true);
                                                 }
                                                 if ($formaction != 'print') {
                                                     //highlight sb or pb if new performance is better
                                                     if ($pb_perf != '' && $perf < $pb_perf) {
                                                         $perf = "<b>PB {$perf}</b>";
                                                     } else {
                                                         if ($sb_perf != '' && $perf < $sb_perf) {
                                                             $perf = "<b>SB {$perf}</b>";
                                                         }
                                                     }
                                                 } else {
                                                     if ($pb_perf != '' && $perf < $pb_perf) {
                                                         $perf = "<b>PB</b> {$perf}";
                                                     } else {
                                                         if ($sb_perf != '' && $perf < $sb_perf) {
                                                             $perf = "<b>SB</b> {$perf}";
                                                         }
                                                     }
                                                 }
                                             }
                                             if (!empty($row_perf['season_effort'])) {
                                                 $sb = "<a href=\"#\" class=\"info\">{$sb_perf}<span>{$row_perf['sb_date']}<br>{$row_perf['season_effort_event']}</span></a>";
                                             } else {
                                                 $sb = "&nbsp;";
                                             }
                                             if (!empty($row_perf['best_effort'])) {
                                                 $pb = "<a href=\"#\" class=\"info\">{$pb_perf}<span>{$row_perf['pb_date']}<br>{$row_perf['best_effort_event']}</span></a>";
                                             } else {
                                                 $pb = "&nbsp;";
                                             }
                                         }
                                     }
                                 }
                                 if ($heatSeparate && $row_res[17] > 0) {
                                     $rank = $count_rank;
                                     if ($row_res[3] < 0) {
                                         // invalid result
                                         $rank = '';
                                     }
                                 }
                                 if ($athleteCat && !$relay) {
                                     $nr++;
                                     if ($rank != '') {
                                         if ($formaction == "print") {
                                             $rank = $nr . ". (" . $rank . ")";
                                         } else {
                                             $rank = $nr . " (" . $rank . ")";
                                         }
                                     }
                                 } else {
                                     if ($formaction == "print") {
                                         if ($rank != '') {
                                             $rank .= ".";
                                         }
                                     }
                                 }
                                 if ($relay) {
                                     $remark = $row_res[17];
                                 } else {
                                     $remark = $row_res[22];
                                 }
                                 if ($wind == '-' && $perf == 0) {
                                     $wind = '';
                                 }
                                 if ($row_res[1] == 999999999) {
                                     $count_show = '';
                                 } else {
                                     $count_show = $count_rank;
                                 }
                                 $list->printLine($count_show, $name, $year, $row_res[8], $perf, $wind, $points, $qual, $ioc, $sb, $pb, $qual_mode, $athleteCat, $remark, '', $withStartnr, $row_res[25]);
                                 if ($secondResult) {
                                     $list->printLine("", "", "", "", $perf2, $wind2, "", "", "", "", "", $qual_mode, "", "", $secondResult);
                                 }
                                 $perf_save = $row_res[3];
                                 // keep performance
                                 //
                                 // if relay, show started ahtletes in right order under the result
                                 //
                                 if ($relay) {
                                     if ($row_res[14] > 0) {
                                         $sqlRound = $row_res[14];
                                     } else {
                                         $sqlRound = $row[0];
                                     }
                                     $res_at = mysql_query("\r\n                                SELECT at.Vorname, at.Name, at.Jahrgang FROM\r\n                                    staffelathlet as sfat\r\n                                    LEFT JOIN start as st ON sfat.xAthletenstart = st.xStart\r\n                                    LEFT JOIN anmeldung as a USING(xAnmeldung)\r\n                                    LEFT JOIN athlet as at USING(xAthlet)\r\n                                WHERE\r\n                                    sfat.xStaffelstart = {$row_res['11']}\r\n                                AND    sfat.xRunde = {$sqlRound} \r\n                                ORDER BY\r\n                                    sfat.Position\r\n                                LIMIT {$row['10']}\r\n                        ");
                                     if (mysql_errno() > 0) {
                                         // DB error
                                         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                     } else {
                                         $text_at = "";
                                         while ($row_at = mysql_fetch_array($res_at)) {
                                             $text_at .= $row_at[1] . " " . $row_at[0] . " " . AA_formatYearOfBirth($row_at[2]) . " / ";
                                         }
                                         $text_at = substr($text_at, 0, strlen($text_at) - 2);
                                         $text_at = trim($text_at) != '' ? '(' . $text_at . ')' : '';
                                         $list->printAthletesLine($text_at);
                                     }
                                 }
                                 //
                                 // if biglist, show all attempts
                                 //
                                 if ($biglist) {
                                     if ($row[3] == $cfgDisciplineType[$strDiscTypeJump] || $row[3] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[3] == $cfgDisciplineType[$strDiscTypeThrow] || $row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                         $query_sort = $row[3] == $cfgDisciplineType[$strDiscTypeHigh] ? "ORDER BY Leistung ASC" : "";
                                         $res_att = mysql_query("\r\n                                SELECT * FROM \r\n                                    resultat \r\n                                WHERE xSerienstart = {$row_res['0']}\r\n                                " . $query_sort . "\r\n                                ");
                                         if (mysql_errno() > 0) {
                                             // DB error
                                             AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
                                         } else {
                                             $text_att = "";
                                             while ($row_att = mysql_fetch_array($res_att)) {
                                                 if ($row_att['Leistung'] < 0) {
                                                     $perf3 = $row_att['Leistung'];
                                                     if ($perf3 == $GLOBALS['cfgMissedAttempt']['db']) {
                                                         // $perf3 = '-';
                                                         $perf3 = $GLOBALS['cfgMissedAttempt']['code'];
                                                     } elseif ($perf3 == $GLOBALS['cfgMissedAttempt']['dbx']) {
                                                         $perf3 = $GLOBALS['cfgMissedAttempt']['codeX'];
                                                     }
                                                     foreach ($cfgInvalidResult as $value) {
                                                         if ($value['code'] == $perf3) {
                                                             $text_att .= $value['short'];
                                                         }
                                                     }
                                                     $text_att .= " / ";
                                                 } else {
                                                     $text_att .= $row_att['Leistung'] == '-' ? '-' : AA_formatResultMeter($row_att['Leistung']);
                                                     if ($saison == "O" || $saison == "I" && $row[3] != $cfgDisciplineType[$strDiscTypeJump]) {
                                                         // outdoor  or (indoor and not jump)
                                                         if ($row_att['Info'] != "-" && !empty($row_att['Info']) && $row[3] != $cfgDisciplineType[$strDiscTypeThrow]) {
                                                             if ($row[3] == $cfgDisciplineType[$strDiscTypeHigh]) {
                                                                 $text_att .= " , " . $row_att['Info'];
                                                             } else {
                                                                 if ($row[8] != 0) {
                                                                     $text_att .= " , " . $row_att['Info'];
                                                                 }
                                                             }
                                                         } elseif ($row_att['Info'] == "-" && $row[3] != $cfgDisciplineType[$strDiscTypeThrow] && $row_att['Leistung'] > 0) {
                                                             $text_att .= " , " . $row_att['Info'];
                                                         }
                                                     }
                                                     $text_att .= " / ";
                                                 }
                                             }
                                             $text_att = substr($text_att, 0, strlen($text_att) - 2);
                                             $list->printAthletesLine("{$strAttempts}: ( {$text_att} )");
                                         }
                                     }
                                 }
                             }
                             // ET athlete processed
                             $id = $row_res[0];
                             // keep current athletes ID
                             if ($relay) {
                                 $catM = $row_res[16];
                             } else {
                                 $catM = $row_res[19];
                             }
                             // keep merged category
                             $info_save1_keep = $info_save1;
                             $info_save2_keep = $info_save2;
                         }
                         // END WHILE result lines
                     }
                     $row1_keep = $row[1];
                     $row2_keep = $row[2];
                 }
             }
             $list->endList();
         }
         //*******************************
         if ($ukc) {
             AA_rankinglist_Combined($category, $formaction, $break, $cover, $sepu23, $cover_timing, $date, $disc_nr, $catFrom, $catTo, $ukc);
         }
         $list->endPage();
         // end HTML page for printing
     }
     // ET DB error event rounds
 }
         // best effort
     }
     if ($pf == 9999999) {
         $pf = 0;
     }
     // show top performance of athletes
     if ($row[6] == $cfgDisciplineType[$strDiscTypeJump] || $row[6] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[6] == $cfgDisciplineType[$strDiscTypeThrow] || $row[6] == $cfgDisciplineType[$strDiscTypeHigh]) {
         $perf = AA_formatResultMeter($pf);
         //$perf = AA_formatResultMeter($row[5]);
     } else {
         if ($row[6] == $cfgDisciplineType[$strDiscTypeTrack] || $row[6] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
             // $perf = AA_formatResultTime($row[5], true, true);
             $perf = AA_formatResultTime($pf, true, true);
         } else {
             //$perf = AA_formatResultTime($row[5], true);
             $perf = AA_formatResultTime($pf, true);
         }
     }
     if ($combined) {
         if ($_GET['event'] == 0) {
             // the whole combined event
             $perf = $pf;
             // points
         }
     }
     $doc->printLine($row[0], $row[1] . " " . $row[2], AA_formatYearOfBirth($row[3]), $row[4], $row[7], $perf);
 } else {
     if ($row[5] >= 9999999) {
         $row[5] = 0;
     }
     if ($keep_stName != $row[2]) {
 function processDiscipline($event, $disctype, $catname, $discname, $windmeas, $list)
 {
     global $rFrom, $rTo, $limitRank, $date;
     require 'config.inc.php';
     $teams = array();
     // team array
     $countRes = 3;
     // results per team counting
     $order_perf = "";
     $valid_result = "";
     if ($disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow]) {
         $order_perf = "DESC";
     } else {
         if ($disctype == $cfgDisciplineType[$strDiscTypeJump]) {
             if ($windmeas == 1) {
                 // with wind
                 $order_perf = "DESC, r.Info ASC";
             } else {
                 // without wind
                 $order_perf = "DESC";
             }
         } else {
             if ($disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $order_perf = "DESC";
                 $valid_result = " AND (r.Info LIKE '%O%' OR r.Leistung < 0)";
             } else {
                 $order_perf = "ASC";
             }
         }
     }
     $sql_leistung = $order_perf == 'ASC' ? "r.Leistung" : "IF(r.Leistung<0, (If(r.Leistung = -99, -9, r.Leistung) * -1), r.Leistung)";
     $res = mysql_query("\r\n\t\tSELECT\r\n\t\t\tts.xTeamsm\r\n\t\t\t, ts.Name\r\n\t\t\t, v.Name\r\n\t\t\t, at.Name\r\n\t\t\t, at.Vorname\r\n\t\t\t, a.Startnummer\r\n\t\t\t, " . $sql_leistung . " AS leistung_neu\r\n\t\t\t, at.xAthlet\r\n\t\tFROM\r\n\t\t\tteamsm AS ts\r\n\t\t\t, verein AS v\r\n\t\t\t, teamsmathlet AS tsa\r\n\t\t\t, anmeldung AS a\r\n\t\t\t, athlet AS at\r\n\t\t\t, start AS st\r\n\t\t\t, serienstart AS ss\r\n\t\t\t, resultat AS r \r\n\t\t\t, serie AS se\r\n\t\t\t, runde as ru\r\n\t\tWHERE\r\n\t\t\tts.xWettkampf = {$event}\r\n\t\tAND\ttsa.xTeamsm = ts.xTeamsm\r\n\t\tAND\tv.xVerein = ts.xVerein\r\n\t\tAND\ta.xAnmeldung = tsa.xAnmeldung\r\n\t\tAND\tat.xAthlet = a.xAthlet\r\n\t\tAND\tst.xAnmeldung = tsa.xAnmeldung\r\n\t\tAND\tst.xWettkampf = {$event}\r\n\t\tAND\tss.xStart = st.xStart\r\n\t\tAND ss.xSerie = se.xSerie\r\n\t\tAND se.xRunde = ru.xRunde\r\n\t\tAND ru.Datum LIKE '" . $date . "'\r\n\t\t\r\n\t\tAND\tr.xSerienstart = ss.xSerienstart\r\n\t\t{$valid_result}\r\n\t\t\r\n\t\tORDER BY\r\n\t\t\tts.xTeamsm\r\n\t\t\t, leistung_neu {$order_perf}\r\n\t");
     if (mysql_errno() > 0) {
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $team = 0;
         // current team
         $c = 0;
         // count results
         $athletes = array();
         $teams_notValid = array();
         // team array
         while ($row = mysql_fetch_array($res)) {
             $row_res[6] = $row_res[6] == 1 || $row_res[6] == 2 || $row_res[6] == 3 || $row_res[6] == 4 ? $row_res[6] * -1 : ($row_res[6] == 9 ? -99 : $row_res[6]);
             if (isset($athletes[$row[7]])) {
                 continue;
             } else {
                 $athletes[$row[7]] = 1;
             }
             if ($team != $row[0]) {
                 if ($team > 0) {
                     $countAthl = count($teams[$team]['athletes']);
                     if ($countAthl < $countRes) {
                         $teams[$team]['perf'] = 0;
                         $teams_notValid[$team]['club'] = $teams[$team]['club'];
                         $teams_notValid[$team]['name'] = $teams[$team]['name'];
                         $teams_notValid[$team]['perf'] = 0;
                         $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
                     } else {
                         $teams[$team]['perf'] /= $countRes;
                     }
                 }
                 $team = $row[0];
                 $teams[$team]['club'] = $row[2];
                 $teams[$team]['name'] = $row[1];
                 $c = 0;
             }
             $perf = 0;
             $perf_print = 0;
             if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                 $perf = $row[6];
                 $perf_print = AA_formatResultMeter($row[6]);
             } else {
                 $perf = ceil($row[6] / 10) * 10;
                 // round up 1000
                 if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                     $perf_print = AA_formatResultTime($row[6], true, true);
                 } else {
                     $perf_print = AA_formatResultTime($row[6], true);
                 }
             }
             if ($c < $countRes) {
                 $teams[$team]['perf'] += $perf;
                 $teams[$team]['athletes'][] = "{$row['3']} {$row['4']}, {$perf_print}";
             } else {
                 $teams[$team]['athletes'][] = "[{$row['3']} {$row['4']}, {$perf_print}]";
             }
             $c++;
         }
         if ($team > 0) {
             // calc last team
             $countAthl = count($teams[$team]['athletes']);
             if ($countAthl < $countRes) {
                 $teams[$team]['perf'] = 0;
                 $teams_notValid[$team]['club'] = $teams[$team]['club'];
                 $teams_notValid[$team]['name'] = $teams[$team]['name'];
                 $teams_notValid[$team]['perf'] = 0;
                 $teams_notValid[$team]['athletes'] = $teams[$team]['athletes'];
             } else {
                 $teams[$team]['perf'] /= $countRes;
             }
         }
         $teams_valid = array();
         foreach ($teams as $k => $arr_team) {
             if (!isset($teams_notValid[$k]['name'])) {
                 $teams_valid[$k]['name'] = $teams[$k]['name'];
                 $teams_valid[$k]['club'] = $teams[$k]['club'];
                 $teams_valid[$k]['perf'] = $teams[$k]['perf'];
                 $teams_valid[$k]['athletes'] = $teams[$k]['athletes'];
             }
         }
         $teams = $teams_valid;
         //
         // print team ranking
         //
         if (count($teams) > 0) {
             $list->printSubTitle($catname, $discname, "");
             $list->startList();
             $list->printHeaderLine();
             usort($teams, "cmp_{$order_perf}");
             // sort by performance
             $teams = array_merge($teams, $teams_notValid);
             $rank = 1;
             // initialize rank
             $r = 0;
             // start value for ranking
             $p = 0;
             foreach ($teams as $team) {
                 $r++;
                 if ($limitRank && ($r < $rFrom || $r > $rTo)) {
                     // limit ranks if set (export)
                     continue;
                 }
                 if ($p != $team['perf']) {
                     // not the same performance
                     $rank = $r;
                     // next rank
                 } else {
                     $rank = '';
                 }
                 $perf = 0;
                 if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                     $perf = AA_formatResultMeter($team['perf']);
                 } else {
                     if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                         $perf = AA_formatResultTime($team['perf'], true, true);
                     } else {
                         $perf = AA_formatResultTime($team['perf'], true);
                     }
                 }
                 if ($perf == 0) {
                     $rank = '';
                 }
                 $list->printLine($rank, $team['name'], $team['club'], $perf);
                 // print each athlete with result for team
                 $tmp = "";
                 foreach ($team['athletes'] as $athlete) {
                     //$list->printInfo($athlete);
                     $tmp .= $athlete . " / ";
                 }
                 $list->printInfo(substr($tmp, 0, -2));
                 $p = $team['perf'];
                 // keep current performance
             }
             $list->endList();
         }
     }
 }
示例#19
0
        
		<td>
<?php 
                            // show combined topperf if last combined discipline
                            if ($combined && $cLast == 1) {
                                $row[8] = $row[17];
                                echo $row[8];
                            } else {
                                if ($row[8] == 0) {
                                    // no top performance set
                                    echo "-";
                                } else {
                                    if ($disctype == $cfgDisciplineType[$strDiscTypeJump] || $disctype == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeThrow] || $disctype == $cfgDisciplineType[$strDiscTypeHigh]) {
                                        echo AA_formatResultMeter($row[8]);
                                    } else {
                                        echo AA_formatResultTime($row[8]);
                                    }
                                }
                            }
                            ?>
		</td>
        
        
        
        
		<?php 
                            if ($disctype == $cfgDisciplineType[$strDiscTypeTrack] || $disctype == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $disctype == $cfgDisciplineType[$strDiscTypeRelay] || $disctype == $cfgDisciplineType[$strDiscTypeDistance]) {
                                ?>
		<td colspan='2'><input type="text" id="newtrack" size="3" value="<?php 
                                echo $tracknumber;
                                ?>
示例#20
0
     $doc->printHeaderLine();
 }
 if ($_GET['list'] == 'team') {
     $disc = '';
     // list of disciplines
     $sql = "SELECT\r\n                            d.Kurzname, d.Typ, s.Bestleistung\r\n                        FROM\r\n                            disziplin_" . $_COOKIE['language'] . " AS d\r\n                            LEFT JOIN wettkampf AS w ON (w.xDisziplin = d.xDisziplin )   \r\n                            LEFT JOIN start AS s ON (s.xWettkampf = w.xWettkampf)  \r\n                        WHERE \r\n                            s.xAnmeldung = {$list_row['0']}                        \r\n                        ORDER BY\r\n                            d.Anzeige";
     $disc_res = mysql_query($sql);
     if (mysql_errno() > 0) {
         AA_printErrorMsg(mysql_errno() . ": " . mysql_error());
     } else {
         $sep = '';
         while ($disc_row = mysql_fetch_row($disc_res)) {
             $disc = $disc . $sep . $disc_row[0];
             // add discipline
             if ($disc_row[1] == $cfgDisciplineType[$strDiscTypeTrack] || $disc_row[1] == $cfgDisciplineType[$strDiscTypeTrackNoWind] || $disc_row[1] == $cfgDisciplineType[$strDiscTypeRelay] || $disc_row[1] == $cfgDisciplineType[$strDiscTypeDistance]) {
                 $perf = AA_formatResultTime($disc_row[2]);
             } else {
                 $perf = AA_formatResultMeter($disc_row[2]);
             }
             if ($perf > 0) {
                 $disc = $disc . "(" . $perf . ")";
             }
             $sep = ", ";
         }
         mysql_free_result($disc_res);
     }
     // ET DB error
     $doc->printLine($list_row[1], $list_row[2] . " " . $list_row[3], AA_formatYearOfBirth($list_row[4]), $disc);
 } else {
     $disc = '';
     if ($list_row[0] != $d) {
示例#21
0
    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);
        }
    }
示例#22
0
            ?>
</th>
        <td class="forms"><input type="text" name="quali" value="<?php 
            echo $quali;
            ?>
"
            onchange="document.teamsm.submit()"></td>
    </tr>
    <?php 
            if ($row[16] == $cfgDisciplineType[$strDiscTypeJump] || $row[16] == $cfgDisciplineType[$strDiscTypeJumpNoWind] || $row[16] == $cfgDisciplineType[$strDiscTypeThrow] || $row[16] == $cfgDisciplineType[$strDiscTypeHigh]) {
                $perf = AA_formatResultMeter($row[15]);
            } else {
                if ($row[16] == $cfgDisciplineType[$strDiscTypeTrack] || $row[16] == $cfgDisciplineType[$strDiscTypeTrackNoWind]) {
                    $perf = AA_formatResultTime($row[15], true, true);
                } else {
                    $perf = AA_formatResultTime($row[15], true);
                }
            }
            if ($perf == 0) {
                $perf = '';
            }
            ?>
    
    <tr>
        <th class="dialog"><?php 
            echo $strQualifyValue;
            ?>
</th>
         <td class="forms"><input type="text" name="perf" value="<?php 
            echo $perf;
            ?>