*
 * Aggiunta per il calcolo della freccia X to win
 *
 * aggiunti 4 campi XML:
 * - xtowin: valore della freccia (e quindi della zona da non scurire). Se 1000 ignorare
 * - totieset: indica se il valore indicato è per vincere o pareggiare il set
 * - towinmatch: indica se il valore indicato è per vincere il match
 * - totiematch: indica se il valore indicato è per pareggiare il match
 *
 * */
$SQL = "SELECT " . " f.FinEvent Event, " . " EvMatchArrowsNo, EvMixedTeam, EvTeamEvent, EvEventName, " . " GrPhase Phase, " . " f.FinVxF," . " IF(f.FinDateTime>=f2.FinDateTime, f.FinDateTime, f2.FinDateTime) AS DateTime," . " TIMESTAMPDIFF(SECOND, IF(f.FinDateTime>=f2.FinDateTime, f.FinDateTime, f2.FinDateTime), now())>90  AS TooOld," . " f.FinMatchNo as MatchNo," . " fs1.FsTarget Target, " . " fs2.FsTarget OppTarget, " . " f2.FinMatchNo as OppMatchNo," . " EvMatchMode!=0 as SetMode, " . " e1.EnId," . " e1.EnFirstName AS AthleteFirstName," . " e1.EnName as AthleteName," . " e1.EnCode as AthleteBib," . " c1.CoCode as CoCode, " . " c1.CoName as CoName, " . " IF(EvMatchMode=0,f.FinScore,f.FinSetScore) AS Score," . " f.FinSetPoints SetPoints," . " f.FinTie as Tie," . " f.FinTieBreak as TieBreak," . " f.FinArrowString as ArrowString, " . " e2.EnId OppEnId," . " e2.EnFirstName AS OpponentFirstName," . " e2.EnName as OpponentName," . " e2.EnCode as OpponentBib," . " c2.CoCode as OppCoCode, " . " c2.CoName as OppCoName, " . " IF(EvMatchMode=0,f2.FinScore,f2.FinSetScore) as OppScore," . " f2.FinSetPoints OppSetPoints," . " f2.FinTie as OppTie," . " f2.FinTieBreak as OppTieBreak," . " f2.FinArrowString as OppArrowString " . "FROM Finals AS f " . "INNER JOIN Finals AS f2 ON f.FinEvent=f2.FinEvent AND f.FinMatchNo=f2.FinMatchNo-1 AND f.FinTournament=f2.FinTournament " . "LEFT JOIN Entries e1 on f.FinAthlete=e1.EnId " . "LEFT JOIN Entries e2 on f2.FinAthlete=e2.EnId " . "LEFT JOIN Countries c1 on e1.EnCountry=c1.CoId " . "LEFT JOIN Countries c2 on e2.EnCountry=c2.CoId " . "LEFT JOIN FinSchedule fs1 on fs1.FSEvent=f.FinEvent and fs1.FSTeamEvent='0' and fs1.FSMatchNo=f.FinMatchNo and f.FinTournament=fs1.FSTournament " . "LEFT JOIN FinSchedule fs2 on fs2.FSEvent=f2.FinEvent and fs2.FSTeamEvent='0' and fs2.FSMatchNo=f2.FinMatchNo and f2.FinTournament=fs2.FSTournament " . "INNER JOIN Events ON f.FinEvent=EvCode AND f.FinTournament=EvTournament AND EvTeamEvent=0 " . "INNER JOIN Grids ON f.FinMatchNo=GrMatchNo " . "WHERE f.FinTournament={$TourId} AND (f.FinMatchNo % 2)=0" . " AND f.FinLive='1' ";
$q = safe_r_sql($SQL);
$r = safe_fetch($q);
$NumArrows = 3;
// Numero di frecce
if (($r->EvMatchArrowsNo & ($r->Phase > 0 ? 2 * bitwisePhaseId($r->Phase) : 1)) !== 0) {
    $NumArrows = 6;
    // Numero di frecce
}
//			if($r->EvMixedTeam) $nARR='2x2';
//			elseif($r->EvTeamEvent) $nARR='3x2';
//$Target=${GetTargetType($r->Event, 0, $TourId)};
$XmlDoc = new DOMDocument('1.0', 'UTF-8');
$XmlRoot = $XmlDoc->createElement('archeryscores');
$XmlDoc->appendChild($XmlRoot);
//$Header = $XmlDoc->createElement('header', get_text($r->Event, null, null, true) . ' - ' . get_text('IndFinEvent', 'Tournament') . ' - ' . get_text($r->Phase.'_Phase'));
$Header = $XmlDoc->createElement('header');
$Header->appendChild($XmlDoc->createCDATASection(get_text($r->EvEventName, null, null, true)));
$XmlRoot->appendChild($Header);
//if($ERROR_REPORT) {
//	$Games = $XmlDoc->createElement('query', $SQL);
Exemple #2
0
function DrawScore(&$pdf, $MyRow, $WhichScore, $WhereX, $WhereY, $FinalScore = false)
{
    global $defTotalW, $defGoldW, $defArrowTotW, $ScoreHeight, $NumFasi, $Fasi, $TgtNoFasi, $Score3D, $Start2FirstPhase;
    $scoreStartX = $WhereX;
    $scoreStartY = $WhereY;
    $TotalW = $defTotalW;
    $GoldW = $defGoldW;
    $NumCol = 3;
    $NumRow = 5;
    $CellH = 6;
    // OCIO al 2*: il motivo è che il bit meno significativo è la finale quindi abbiamo tutto traslato a sinistra di un bit (=moltiplicato per due)
    if ($MyRow->EvMatchArrowsNo & 2 * bitwisePhaseId($NumFasi[$WhichScore])) {
        // eliminatorie
        $NumRow = $MyRow->EvElimEnds;
        $NumCol = $MyRow->EvElimArrows;
        $NumSO = $MyRow->EvElimSO;
    } else {
        $NumRow = $MyRow->EvFinEnds;
        $NumCol = $MyRow->EvFinArrows;
        $NumSO = $MyRow->EvFinSO;
    }
    //print $WhichScore.'<br>';
    $ArrowW = $defArrowTotW / $NumCol;
    $CellH = ($ScoreHeight - 6 * 5) / $NumRow;
    //Header
    $pdf->SetFont($pdf->FontStd, 'B', 10);
    $pdf->SetXY($WhereX, $WhereY);
    $pdf->Cell($GoldW, 6, '', 0, 0, 'C', 0);
    $pdf->Cell(2 * $GoldW + 2 * $TotalW + $NumCol * $ArrowW, 6, $Fasi[$WhichScore], 1, is_null($MyRow->{$TgtNoFasi[$WhichScore]}) ? 1 : 0, 'C', 1);
    if (!is_null($MyRow->{$TgtNoFasi[$WhichScore]})) {
        $pdf->SetXY($pdf->GetX() - 15, $pdf->GetY());
        if (!$FinalScore) {
            $pdf->SetFont($pdf->FontStd, '', 6);
            $pdf->Cell(15, 3, get_text('Target'), 'LRT', 0, 'C', 1);
            $pdf->SetFont($pdf->FontStd, 'B', 7);
            $pdf->SetXY($pdf->GetX() - 15, $pdf->GetY() + 3);
            $pdf->Cell(15, 3, ltrim($MyRow->{$TgtNoFasi[$WhichScore]}, 0), 'LRB', 0, 'C', 1);
        } else {
            $pdf->SetFont($pdf->FontStd, 'B', 7);
            $pdf->Cell(15, 3, get_text('MedalGold') . ' ' . ltrim($MyRow->sGo, '0'), 'LRT', 0, 'C', 1);
            $pdf->SetXY($pdf->GetX() - 15, $pdf->GetY() + 3);
            $pdf->Cell(15, 3, get_text('MedalBronze') . ' ' . ltrim($MyRow->sBr, '0'), 'LRB', 0, 'C', 1);
        }
    }
    $pdf->Rect($WhereX + $GoldW + 1, $WhereY + 1, 4, 4, 'DF', array(), array(255, 255, 255));
    $pdf->SetDefaultColor();
    $pdf->SetXY($WhereX + $GoldW + 5, $WhereY + 1);
    $pdf->SetFont($pdf->FontStd, 'B', 6);
    $pdf->Cell($NumCol * $ArrowW - 5, 4, get_text('Winner'), 0, 1, 'L', 0);
    $pdf->SetXY($pdf->GetX(), $WhereY + 6);
    $WhereY = $pdf->GetY();
    //Intestazioni Colonne
    $pdf->SetFont($pdf->FontStd, 'B', 8);
    $pdf->SetXY($WhereX, $WhereY);
    $pdf->Cell($GoldW, 6, '', 0, 0, 'C', 0);
    if ($Score3D) {
        $pdf->Cell($NumCol * $ArrowW, 6, get_text('Arrow'), 1, 0, 'C', 1);
    } else {
        for ($j = 0; $j < $NumCol; $j++) {
            $pdf->Cell($ArrowW, 6, $j + 1, 1, 0, 'C', 1);
        }
    }
    $pdf->Cell($TotalW * ($MyRow->EvMatchMode == 0 ? 1 : 4 / 5), 6, get_text($MyRow->EvMatchMode == 0 ? 'TotalProg' : 'SetTotal', 'Tournament'), 1, 0, 'C', 1);
    $pdf->Cell($TotalW * ($MyRow->EvMatchMode == 0 ? 1 : 4 / 5), 6, get_text($MyRow->EvMatchMode == 0 ? 'TotalShort' : 'RunningTotal', 'Tournament'), 1, 0, 'C', 1);
    if ($MyRow->EvMatchMode == 0) {
        $pdf->Cell($GoldW, 6, $pdf->prnGolds, 1, 0, 'C', 1);
        $pdf->Cell($GoldW, 6, $pdf->prnXNine, 1, 1, 'C', 1);
    } else {
        $pdf->Cell(2 * $GoldW, 6, get_text('SetPoints', 'Tournament'), 1, 0, 'C', 1);
        $pdf->Cell(2 / 5 * $TotalW, 6, get_text('TotalShort', 'Tournament'), 1, 1, 'C', 1);
    }
    $WhereY = $pdf->GetY();
    //Righe
    for ($i = 1; $i <= $NumRow; $i++) {
        $pdf->SetFont($pdf->FontStd, 'B', 10);
        $pdf->SetXY($WhereX, $WhereY);
        $pdf->Cell($GoldW, $CellH, $i, 1, 0, 'C', 1);
        if ($Score3D) {
            $pdf->SetFont($pdf->FontStd, '', 8);
            $pdf->Cell(1 / 5 * $ArrowW, $CellH, '11', 1, 0, 'C', 0);
            $pdf->Cell(1 / 5 * $ArrowW, $CellH, '10', 1, 0, 'C', 0);
            $pdf->Cell(1 / 5 * $ArrowW, $CellH, '8', 1, 0, 'C', 0);
            $pdf->Cell(1 / 5 * $ArrowW, $CellH, '5', 1, 0, 'C', 0);
            $pdf->Cell(1 / 5 * $ArrowW, $CellH, 'M', 1, 0, 'C', 0);
        } else {
            for ($j = 0; $j < $NumCol; $j++) {
                $pdf->Cell($ArrowW, $CellH, '', 1, 0, 'C', 0);
            }
        }
        $pdf->Cell($TotalW * ($MyRow->EvMatchMode == 0 ? 1 : 4 / 5), $CellH, '', 1, 0, 'C', 0);
        $pdf->Cell($TotalW * ($MyRow->EvMatchMode == 0 ? 1 : 4 / 5), $CellH, '', 1, 0, 'C', 0);
        if ($MyRow->EvMatchMode == 0) {
            $pdf->Cell($GoldW, $CellH, '', 1, 0, 'C', 0);
            $pdf->Cell($GoldW, $CellH, '', 1, 1, 'C', 0);
        } else {
            $pdf->SetFont($pdf->FontStd, 'B', 10);
            $pdf->Cell(2 * $GoldW / 3, $CellH, '2', 1, 0, 'C', 0);
            $pdf->Cell(2 * $GoldW / 3, $CellH, '1', 1, 0, 'C', 0);
            $pdf->Cell(2 * $GoldW / 3, $CellH, '0', 1, 0, 'C', 0);
            $pdf->Cell($TotalW * 2 / 5, $CellH, '', 1, 1, 'C', 0);
        }
        $WhereY = $pdf->GetY();
    }
    //Shoot Off
    $pdf->SetXY($WhereX, $WhereY + 0.5);
    $pdf->SetFont($pdf->FontStd, 'B', 8);
    $pdf->Cell($GoldW, 6.5, get_text('TB'), 1, 0, 'C', 1);
    $ShootOffW = $NumSO <= $NumCol ? $ArrowW : $ArrowW * $NumCol / $NumSO;
    for ($j = 0; $j < $NumSO; $j++) {
        $pdf->SetXY($pdf->GetX() + 0.5, $pdf->GetY());
        $pdf->Cell($ShootOffW - 0.5, 4, '', 1, 0, 'C', 0);
    }
    $pdf->SetXY($WhereX + $GoldW + 0.5, $WhereY + 5);
    $pdf->SetFont($pdf->FontStd, '', 1);
    $pdf->Cell(2, 2, '', 1, 0, 'R', 0);
    $pdf->SetXY($WhereX + $GoldW + 2.5, $WhereY + 4.5);
    $pdf->SetFont($pdf->FontStd, '', 6);
    $pdf->Cell($ArrowW * $NumCol - 2.5, 2.5, get_text('Close2Center', 'Tournament'), 0, 0, 'L', 0);
    //Totale
    $pdf->SetXY($WhereX + $GoldW + $ArrowW * $NumCol, $WhereY);
    $pdf->SetFont($pdf->FontStd, 'B', 10);
    if ($MyRow->EvMatchMode == 0) {
        $pdf->Cell($TotalW, 6, get_text('Total'), 0, 0, 'R', 0);
        $pdf->Cell($TotalW, 6, '', 1, 0, 'C', 0);
        $pdf->Cell($GoldW, 6, '', 1, 0, 'C', 0);
        $pdf->Cell($GoldW, 6, '', 1, 1, 'C', 0);
    } else {
        $pdf->Cell($TotalW * 8 / 5, 6, '', 0, 0, 'R', 0);
        $pdf->Cell(2 * $GoldW, 6, get_text('Total'), 0, 0, 'R', 0);
        $pdf->Cell(2 / 5 * $TotalW, 6, '', 1, 1, 'C', 0);
    }
    $WhereY = $pdf->GetY() + 3;
    //Firme
    $pdf->SetXY($WhereX, $WhereY);
    $pdf->SetFont($pdf->FontStd, 'I', 7);
    $pdf->Cell(2 * $defTotalW + $defArrowTotW + 3 * $defGoldW, 4, get_text('Archer'), 'B', 0, 'L', 0);
    $WhereY = $pdf->GetY() + 5;
    $pdf->SetXY($WhereX, $WhereY);
    $pdf->Cell(2 * $defTotalW + $defArrowTotW + 3 * $defGoldW, 4, get_text('Scorer'), 'B', 0, 'L', 0);
    $WhereY = $pdf->GetY();
    if ($MyRow->isBye && $WhichScore == $Start2FirstPhase[$MyRow->EvFinalFirstPhase]) {
        $pdf->SetLineWidth(0.75);
        $pdf->Line($scoreStartX, $scoreStartY, $scoreStartX + (2 * $defTotalW + $defArrowTotW + 3 * $defGoldW), $scoreStartY + $ScoreHeight);
        $pdf->SetLineWidth(0.1);
    }
}
function elimFinFromMatchArrowsNo($firstPhase, $matchArrowsNo)
{
    /*
     * Calcolo l'esponente di 2 per ottenere la fase.
     * Devo moltiplicare per due perchè il bit meno significativo rappresenta
     * la fase zero quindi devo traslare a sinistra di 1 bit che equivale a fare un *2
     */
    $bit = $firstPhase > 0 ? 2 * bitwisePhaseId($firstPhase) : 1;
    // questo è l'esponente!
    $e = log($bit, 2);
    //print 'e: '.$e.'<br><br>';
    //print (pow(2,$e+1)-1).'<br>';
    /*
     * L'and di $matchArrowsNo con il valore mi serve per buttare a zero tutti i bit più a sinistra di $matchArrowsNo
     * che sono successivi a quello della prima fase buona ($firstPhase).
     * Questo mi assicura di che alla fine $rif avrà (escludendo i bit più significativi a zero)tanti bit quante sono
     * le fasi a partire da  $firstPhase
     */
    $rif = $matchArrowsNo & pow(2, $e + 1) - 1;
    $elim = true;
    $fin = true;
    // se non ci sono "1" vuol dire "nessuna fase usa la prima terna"
    if ($rif == 0) {
        $elim = false;
    }
    // se non ci sono "0" vuol dire "nessuna fase usa la seconda terna"
    if ($rif == 1) {
        $fin = false;
    }
    //	print '<pre>';
    //	print_r(array($elim,$fin));
    //	print '</pre>';
    return array($elim, $fin);
}
    $Rs = safe_r_sql($Select);
    if (safe_num_rows($Rs) == 1) {
        $MyRow = safe_fetch($Rs);
        print '<input type="hidden" name="d_Event2Set" value="' . $_REQUEST['d_Event'] . '">';
        print '<table class="Tabella">' . "\n";
        print '<tr><th rowspan="3">' . get_text('RoundDefinition') . '</th>' . '<th colspan="3">' . get_text('Elimination') . (!empty($ErrMsg['Elim']) ? '<div class="red">' . implode('<br/>', $ErrMsg['Elim']) . '</div>' : '') . '</th>' . '<th colspan="3">' . get_text('MenuLM_Final Rounds') . (!empty($ErrMsg['Fin']) ? '<div class="red">' . implode('<br/>', $ErrMsg['Fin']) . '</div>' : '') . '</th></tr>' . "\n";
        print '<tr>' . '<th>' . get_text('Ends', 'Tournament') . '</th>' . '<th>' . get_text('Arrows', 'Tournament') . '</th>' . '<th>' . get_text('ShotOff', 'Tournament') . '</th>' . '<th>' . get_text('Ends', 'Tournament') . '</th>' . '<th>' . get_text('Arrows', 'Tournament') . '</th>' . '<th>' . get_text('ShotOff', 'Tournament') . '</th></tr>' . "\n";
        print '<tr>' . '<td align="center" width="10%"><input size="3" name="ElimEnds" value="' . $MyRow->EvElimEnds . '"/></td>' . '<td align="center" width="10%"><input size="3" name="ElimArrows" value="' . $MyRow->EvElimArrows . '"/></td>' . '<td align="center" width="10%"><input size="3" name="ElimSO" value="' . $MyRow->EvElimSO . '"/></td>' . '<td align="center" width="10%"><input size="3" name="FinEnds" value="' . $MyRow->EvFinEnds . '"/></td>' . '<td align="center" width="10%"><input size="3" name="FinArrows" value="' . $MyRow->EvFinArrows . '"/></td>' . '<td align="center" width="10%"><input size="3" name="FinSO" value="' . $MyRow->EvFinSO . '"/></td>' . '</tr>' . "\n";
        print '<tr><th>' . get_text('Phase') . '</th><th colspan="3">' . get_text('Arr4Set', 'Tournament') . '</th><th colspan="3">' . get_text('Arr4Set', 'Tournament') . '</th></tr>' . "\n";
        for ($CurPhase = $MyRow->StartPhase; $CurPhase >= 0; $CurPhase > 1 ? $CurPhase /= 2 : --$CurPhase) {
            $CurPhase = $CurPhase == 12 ? 16 : $CurPhase;
            print '<tr>';
            print '<td class="Center">' . get_text($CurPhase . '_Phase') . '</td>';
            print '<td class="Center" colspan="3">';
            // Estraggo il bit corrispondete alla fase
            $Bit = $CurPhase > 0 ? 2 * bitwisePhaseId($CurPhase) : 1;
            $Value = ($Bit & $MyRow->BitMask) == $Bit ? 1 : 0;
            $e = log($Bit, 2);
            // esponente di 2 per ottenere la fase
            print '<input type="radio" name="d_EvMatchArrowsNo_' . $e . '"' . ($Value == 1 ? ' checked="checked"' : '') . ' value="1">';
            print '</td>';
            print '<td class="Center" colspan="3">';
            print '<input type="radio" name="d_EvMatchArrowsNo_' . $e . '"' . ($Value == 0 ? ' checked="checked"' : '') . ' value="0">';
            print '</td>';
            print '</tr>' . "\n";
        }
        print '<tr><td colspan="7" class="Center"><input type="submit" value="' . get_text('CmdSave') . '" onclick="document.Frm.Command.value=\'SAVE\'">&nbsp;<input type="reset" value="' . get_text('CmdCancel') . '">';
        print '</table>' . "\n";
    }
}
?>
function old_DecodeArrowstring($matchMode, $matchArrowsNo, $team, $mixedTeam, $phase, $arrowstring, $target)
{
    $ret = '';
    // individuale cumulativo
    $rows = 4;
    $cols = 3;
    if ($team == 1) {
        $rows = 4;
        if ($mixedTeam == 0) {
            $cols = 6;
        } else {
            $cols = 4;
        }
    }
    if ($matchMode == 1) {
        $bit = $phase > 0 ? 2 * bitwisePhaseId($phase) : 1;
        $value = ($bit & $matchArrowsNo) == $bit ? 1 : 0;
        if ($team == 0) {
            if ($value == 0) {
                $rows = 5;
                $cols = 3;
            } else {
                $rows = 3;
                $cols = 6;
            }
        } else {
            if ($value == 0) {
                $rows = 4;
                $cols = 6;
            } else {
                $rows = 4;
                $cols = 6;
            }
        }
    }
    $r = array();
    for ($i = 0; $i < $rows; ++$i) {
        $c = array();
        for ($j = 0; $j < $cols; ++$j) {
            $idx = $i * $cols + $j;
            if (!isset($arrowstring[$idx])) {
                $arrowstring[$idx] = ' ';
            }
            $c[] = DecodeFromLetter($arrowstring[$idx]);
        }
        $r[] = implode(',', $c);
    }
    return implode('-', $r);
}
Exemple #6
0
    case 'T':
        $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=1 AND EvFinalFirstPhase!=0 order by EvProgr";
        break;
    case 'E1':
        $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 and EvElim1>0 AND EvFinalFirstPhase!=0 order by EvProgr";
        break;
    case 'E2':
        $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 and EvElim2>0 AND EvFinalFirstPhase!=0 order by EvProgr";
        break;
    default:
        $SQL = "SELECT EvCode, EvEventName, EvFinalFirstPhase FROM Events WHERE EvTournament={$CompId} AND EvTeamEvent=0 AND EvFinalFirstPhase!=0 order by EvProgr";
}
// Retrieve the Event List
$q = safe_r_sql($SQL);
while ($r = safe_fetch($q)) {
    $tmpPhases = array();
    if ($EventType[0] == 'E') {
        $t = safe_r_sql("select distinct left(ElTargetNo, 3) TargetNo\r\n\t\t\t\tfrom Eliminations\r\n\t\t\t\twhere ElTournament={$CompId}\r\n\t\t\t\t\tand ElElimPhase=" . ($EventType[1] - 1) . "\r\n\t\t\t\t\tand ElEventCode='{$r->EvCode}'\r\n\t\t\t\t\tand ElTargetNo>''\r\n\t\t\t\torder by TargetNo");
        while ($u = safe_fetch($t)) {
            $tmpPhases[] = array("code" => "{$EventType}|{$r->EvCode}|{$u->TargetNo}", "name" => (int) $u->TargetNo);
        }
    } else {
        $phases = getPhasesId($r->EvFinalFirstPhase);
        foreach ($phases as $ph) {
            $tmpPhases[] = array("code" => bitwisePhaseId($ph), "name" => $ph . "_Phase");
        }
    }
    $json_array[] = array("code" => $r->EvCode, "name" => $r->EvEventName, "phases" => $tmpPhases);
}
// Return the json structure with the callback function that is needed by the app
SendResult($json_array);