$results = calculateResult($res, $nb_radio);
            }
            /*else*/
            if ($arr_radio != null) {
                $rid = implode(', ', $arr_radio);
                $sql = "SELECT cmp.id AS id, cmp.name AS name, org.name AS team, radio.ctrl, radio.timestamp, radio.rt AS time, 1 AS status " . "FROM mopradio AS radio, mopcompetitor AS cmp " . "LEFT JOIN moporganization AS org ON cmp.org = org.id AND cmp.cid = org.cid " . "WHERE radio.ctrl IN(" . $rid . ") " . "AND radio.id=cmp.id " . "AND cmp.cls='{$cls}' " . "AND cmp.cid = '{$cmpId}' AND radio.cid = '{$cmpId}' " . "ORDER BY radio.id ASC, radio.rt ASC ";
                $res = mysql_query($sql);
                $results = addRadioResult($res, $results);
            }
            formatResultScreen($results, $limit);
        }
    } else {
        // Single leg (patrol etc)
        if ($radio != '') {
            if ($radio == 'finish') {
                $sql = "SELECT t.id AS id, cmp.name AS name, cmp.timestamp, t.name AS team, t.rt AS time, t.stat AS status " . "FROM mopteammember tm, mopcompetitor cmp, mopteam t " . "WHERE t.cls = '{$cls}' AND t.id = tm.id AND tm.rid = cmp.id AND tm.leg=1 " . "AND t.cid = '{$cmpId}' AND tm.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' " . "AND ((t.stat>0) OR ((t.stat=0) AND ((SELECT COUNT(*) FROM mopradio AS mr WHERE mr.cid='{$cmpId}' AND tm.rid=mr.id) > 0)))" . "ORDER BY t.stat ASC, t.rt ASC, t.id";
                $rname = "Finish";
                $res = mysql_query($sql);
                $results = calculateResult($res, $nb_radio);
            }
            /*else*/
            if ($arr_radio != null) {
                $rid = implode(', ', $arr_radio);
                $sql = "SELECT team.id AS id, cmp.name AS name, team.name AS team, radio.rt AS time, radio.timestamp, 1 AS status " . "FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp " . "WHERE radio.ctrl IN(" . $rid . ") " . "AND radio.id=cmp.id " . "AND m.rid = radio.id " . "AND m.id = team.id " . "AND m.leg=1 " . "AND cmp.cls='{$cls}' " . "AND radio.cid = '{$cmpId}' AND m.cid = '{$cmpId}' AND team.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' " . "ORDER BY radio.id ASC, radio.rt ASC ";
                $res = mysql_query($sql);
                $results = addRadioResult($res, $results);
            }
            formatResultScreen($results, $limit);
        }
    }
}
            formatResultScreen($results3);
        }
    } else {
        // Single leg (patrol etc)
        //$radio = selectRadio($cls);
        if ($radio != '') {
            if ($radio == 'finish') {
                $sql = "SELECT t.id AS id, cmp.name AS name, cmp.st, t.name AS team, t.rt AS time, t.stat AS status " . "FROM mopteammember tm, mopcompetitor cmp, mopteam t " . "WHERE t.cls = '{$cls}' AND t.id = tm.id AND tm.rid = cmp.id AND tm.leg=1 " . "AND t.cid = '{$cmpId}' AND tm.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' ORDER BY cmp.st ASC, t.stat, t.rt ASC, t.id";
                $sql2 = "SELECT t.id AS id, cmp.name AS name, cmp.st, t.name AS team, t.rt AS time, t.stat AS status " . "FROM mopteammember tm, mopcompetitor cmp, mopteam t " . "WHERE t.cls = '{$cls}' AND t.id = tm.id AND tm.rid = cmp.id AND tm.leg=1 " . "AND t.cid = '{$cmpId}' AND tm.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' ORDER BY cmp.name ASC, cmp.st ASC, t.stat, t.rt ASC, t.id";
                $rname = "Finish";
            } else {
                $rid = (int) $radio;
                $sql = "SELECT name FROM mopcontrol WHERE cid='{$cmpId}' AND id='{$rid}'";
                $res = mysql_query($sql);
                $rinfo = mysql_fetch_array($res);
                $rname = $rinfo['name'];
                $sql = "SELECT team.id AS id, cmp.name AS name, cmp.st, team.name AS team, radio.rt AS time, 1 AS status " . "FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp " . "WHERE radio.ctrl='{$rid}' " . "AND radio.id=cmp.id " . "AND m.rid = radio.id " . "AND m.id = team.id " . "AND m.leg=1 " . "AND cmp.cls='{$cls}' " . "AND radio.cid = '{$cmpId}' AND m.cid = '{$cmpId}' AND team.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' " . "ORDER BY cmp.st ASC, radio.rt ASC ";
                $sql2 = "SELECT team.id AS id, cmp.name AS name, cmp.st, team.name AS team, radio.rt AS time, 1 AS status " . "FROM mopradio AS radio, mopteammember AS m, mopteam AS team, mopcompetitor AS cmp " . "WHERE radio.ctrl='{$rid}' " . "AND radio.id=cmp.id " . "AND m.rid = radio.id " . "AND m.id = team.id " . "AND m.leg=1 " . "AND cmp.cls='{$cls}' " . "AND radio.cid = '{$cmpId}' AND m.cid = '{$cmpId}' AND team.cid = '{$cmpId}' AND cmp.cid = '{$cmpId}' " . "ORDER BY cmp.name ASC, cmp.st ASC, radio.rt ASC ";
            }
            $res = mysql_query($sql);
            $results = calculeStart($res);
            $res2 = mysql_query($sql2);
            $results2 = calculeStart($res2);
            $results3 = null;
            foreach ($results as $i => $v) {
                $results3[] = array($results[$i]['start_time'], $results[$i]['name'], $results[$i]['team'], $results2[$i]['name'], $results2[$i]['team'], $results2[$i]['start_time']);
            }
            formatResultScreen($results3);
        }
    }
}