Ejemplo n.º 1
0
        if ($rs) {
            $count = safe_num_rows($rs);
            $countryCode = mb_convert_case($countryCode, MB_CASE_UPPER, "UTF-8");
            // se non c'è lo aggiungo
            if ($count == 0) {
                $query = "INSERT INTO Countries (CoTournament,CoCode,CoName) " . "VALUES(" . $tourId . "," . StrSafe_DB($countryCode) . "," . "''" . ") ";
                $rs = safe_w_sql($query);
                if ($rs) {
                    $coId = safe_w_last_id();
                } else {
                    $error = 1;
                }
            } elseif ($count == 1) {
                $myRow = safe_fetch($rs);
                //$coName=$myRow->CountryName;
                $coName = AdjustCaseTitle($myRow->CoName);
                $coId = $myRow->CoId;
            } else {
                $error = 1;
            }
        } else {
            $error = 1;
        }
    }
} else {
    $error = 1;
}
if ($error == 0) {
    $query = "UPDATE " . "Entries " . "SET " . "EnCountry3=" . StrSafe_DB($coId) . " " . "WHERE " . "EnId=" . StrSafe_DB($id) . " ";
    $rs = safe_w_sql($query);
    if (!$rs) {
Ejemplo n.º 2
0
     case 'division':
         $resetPrintBadge = true;
         $query = "SELECT EnDivision FROM Entries WHERE EnId=" . StrSafe_DB($id) . " AND EnDivision<>" . StrSafe_DB($value) . " ";
         $rs = safe_r_sql($query);
         if ($rs && safe_num_rows($rs) == 1) {
             $recalc = true;
             // prendo le vecchie impostazioni
             $x = Params4Recalc($id);
             if ($x !== false) {
                 list($indFEventOld, $teamFEventOld, $countryOld, $divOld, $clOld, $zeroOld) = $x;
             }
         }
         break;
     case 'first_name':
     case 'name':
         $value = AdjustCaseTitle($value);
         $resetPrintBadge = true;
         break;
     case '':
         break;
 }
 $query = "UPDATE " . "Entries " . " " . "SET " . $entriesMapping[$field] . "=" . StrSafe_DB($value) . " " . ($resetPrintBadge ? ", EnBadgePrinted='0000-00-00 00:00:00'" : "") . "WHERE " . "EnId=" . StrSafe_DB($id) . " ";
 $rs = safe_w_sql($query);
 //print $query;exit;
 if (!$rs) {
     $error = 1;
 } else {
     // dopo
     if ($recalc) {
         $x = Params4Recalc($id);
         if ($x !== false) {
Ejemplo n.º 3
0
             list($indFEventOld, $teamFEventOld, $countryOld, $divOld, $clOld, $zeroOld) = $x;
         }
     }
     // se la vecchia matricola è diversa Azzero la foto
     $query = "SELECT EnCode FROM Entries WHERE EnId=" . StrSafe_DB($id) . " AND EnCode<>" . StrSafe_DB($_REQUEST['d_e_EnCode_']);
     //print $query;exit;
     $rs = safe_r_sql($query);
     if ($rs && safe_num_rows($rs) == 1) {
         $query = "DELETE FROM " . "Photos " . "WHERE " . "PhEnId=" . StrSafe_DB($id) . " ";
         $rs = safe_w_sql($query);
     }
 } else {
     $recalc = true;
 }
 $EnName = AdjustCaseTitle($_REQUEST['d_e_EnName_']);
 $EnFirstName = AdjustCaseTitle($_REQUEST['d_e_EnFirstName_']);
 $Insert = "INSERT INTO Entries (EnId,EnIocCode,EnTournament,EnDivision,EnClass,EnAthlete,EnSubClass,EnAgeClass,EnCountry,EnSubTeam,EnCountry2,EnCountry3,EnDob,EnCode,EnName,EnFirstName,EnSex,EnTargetFace,EnStatus,EnIndClEvent,EnTeamClEvent,EnIndFEvent,EnTeamFEvent,EnTeamMixEvent,EnWChair,EnDoubleSpace) " . "VALUES(" . ($id != 0 ? StrSafe_DB($id) : "''") . "," . StrSafe_DB($_REQUEST['LupSelect']) . "," . StrSafe_DB($_SESSION['TourId']) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnDivision_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnClass_'])) . "," . StrSafe_DB($EnAthlete) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnSubClass_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnAgeClass_'])) . "," . StrSafe_DB($EnCountries['']) . "," . StrSafe_DB($_REQUEST['d_e_EnSubTeam_']) . "," . StrSafe_DB($EnCountries['2']) . "," . StrSafe_DB($EnCountries['3']) . "," . StrSafe_DB(trim($EnDob)) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnCode_'])) . "," . StrSafe_DB($EnName) . "," . StrSafe_DB($EnFirstName) . "," . StrSafe_DB($_REQUEST['d_e_EnSex_']) . "," . StrSafe_DB($_REQUEST['d_e_EnTargetFace_']) . "," . StrSafe_DB($_REQUEST['d_e_EnStatus_']) . ", " . StrSafe_DB(trim($_REQUEST['d_e_EnIndClEvent_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnTeamClEvent_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnIndFEvent_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnTeamFEvent_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnTeamMixEvent_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnWChair_'])) . "," . StrSafe_DB(trim($_REQUEST['d_e_EnDoubleSpace_'])) . " " . ") ON DUPLICATE KEY UPDATE " . "EnIocCode=" . StrSafe_DB(trim($_REQUEST['LupSelect'])) . "," . "EnDivision=" . StrSafe_DB(trim($_REQUEST['d_e_EnDivision_'])) . "," . "EnClass=" . StrSafe_DB(trim($_REQUEST['d_e_EnClass_'])) . "," . "EnAthlete=" . StrSafe_DB($EnAthlete) . "," . "EnSubClass=" . StrSafe_DB(trim($_REQUEST['d_e_EnSubClass_'])) . "," . "EnAgeClass=" . StrSafe_DB(trim($_REQUEST['d_e_EnAgeClass_'])) . "," . "EnCountry=" . StrSafe_DB($EnCountries['']) . "," . "EnSubTeam=" . StrSafe_DB($_REQUEST['d_e_EnSubTeam_']) . "," . "EnCountry2=" . StrSafe_DB($EnCountries['2']) . "," . "EnCountry3=" . StrSafe_DB($EnCountries['3']) . "," . "EnDob=" . StrSafe_DB($EnDob) . "," . "EnCode=" . StrSafe_DB(trim($_REQUEST['d_e_EnCode_'])) . "," . "EnName=" . StrSafe_DB($EnName) . "," . "EnFirstName=" . StrSafe_DB($EnFirstName) . "," . "EnSex=" . StrSafe_DB($_REQUEST['d_e_EnSex_']) . "," . "EnTargetFace=" . StrSafe_DB($_REQUEST['d_e_EnTargetFace_']) . "," . "EnStatus=" . StrSafe_DB($_REQUEST['d_e_EnStatus_']) . ", " . "EnIndClEvent=" . StrSafe_DB($_REQUEST['d_e_EnIndClEvent_']) . "," . "EnTeamClEvent=" . StrSafe_DB($_REQUEST['d_e_EnTeamClEvent_']) . "," . "EnIndFEvent=" . StrSafe_DB($_REQUEST['d_e_EnIndFEvent_']) . "," . "EnTeamFEvent=" . StrSafe_DB($_REQUEST['d_e_EnTeamFEvent_']) . "," . "EnTeamMixEvent=" . StrSafe_DB($_REQUEST['d_e_EnTeamMixEvent_']) . "," . "EnWChair=" . StrSafe_DB($_REQUEST['d_e_EnWChair_']) . "," . "EnDoubleSpace=" . StrSafe_DB($_REQUEST['d_e_EnDoubleSpace_']) . " ";
 $Rs = safe_w_sql($Insert);
 if ($id == 0) {
     $id = safe_w_last_id();
 }
 if (safe_w_affected_rows()) {
     safe_w_sql("update Entries set EnBadgePrinted=0 where EnId={$id}");
 }
 //print $Insert.'<br><br/>';
 if ($Op == 'Ins') {
     // aggiungo la riga in Qualifications
     $Insert = "INSERT INTO Qualifications (QuId,QuSession) " . "VALUES(" . StrSafe_DB($id) . "," . "0" . ") ";
     $Rs = safe_w_sql($Insert);
     //print $Insert.'<br><br>';
 }
Ejemplo n.º 4
0
function UpdateTournament($Gara)
{
    if ($Gara['Tournament']['ToDbVersion'] < '2010-04-13 14:00:00') {
        // rimedia all'errore introdotto in Arizona e spota il flag da DoubleSpace a WChair
        foreach ($Gara['Entries'] as $ID => $Entry) {
            if (!empty($Entry['EnDoubleSpace'])) {
                $Gara['Entries'][$ID]['EnWChair'] = '1';
                $Gara['Entries'][$ID]['EnDoubleSpace'] = '0';
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-04-17 15:34:01') {
        if (empty($Gara['TournamentDistances'])) {
            // recupera le differenti classi delle entries e le mette in una tabella temporanea
            safe_w_sql("create temporary table TempClasses (TcClass varchar(5) not null, primary key (TcClass) )");
            foreach ($Gara['Entries'] as $E) {
                safe_w_sql("insert ignore into TempClasses set TcClass='" . $E['EnDivision'] . $E['EnClass'] . "'");
            }
            // riempie la tabella con le occorrenze
            $Gara['TournamentDistances'] = array();
            $t = safe_r_sql("SELECT distinct td.* FROM TournamentDistances td inner join TempClasses e on TcClass LIKE TdClasses where TdType='{$Gara['Tournament']['ToType']}' and TdTournament=0");
            while ($u = safe_fetch($t)) {
                $u->TdTournament = $Gara['Tournament']['ToId'];
                $qubits = array();
                foreach ($u as $key => $val) {
                    $qubits[$key] = $val;
                }
                $Gara['TournamentDistances'][] = $qubits;
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-04-25 11:34:00') {
        // procedura di aggiornamento della gara alla versione attuale del database
        foreach ($Gara['Entries'] as $ID => $data) {
            if (array_key_exists('EnPhoto', $Gara['Entries'][$ID])) {
                $Gara['Entries'][$ID]['EnBadgePrinted'] = $Gara['Entries'][$ID]['EnPhoto'];
                unset($Gara['Entries'][$ID]['EnPhoto']);
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-09-01 10:15:00') {
        //print $Gara['Tournament']['ToType'];exit;
        // aggiungo le colonne nuove alla Tournament
        $Gara['Tournament']['ToLocRule'] = '';
        $Gara['Tournament']['ToUpNamesUrl'] = '';
        $Gara['Tournament']['ToUpPhotosUrl'] = '';
        $Gara['Tournament']['ToUpFlagsUrl'] = '';
        //		$Gara['Tournament']['ToTypeName']='';
        //		$Gara['Tournament']['ToNumDist']='0';
        //		$Gara['Tournament']['ToNumEnds']='0';
        //		$Gara['Tournament']['ToMaxDistScore']='0';
        //		$Gara['Tournament']['ToMaxFinIndScore']='0';
        //		$Gara['Tournament']['ToMaxFinTeamScore']='0';
        //		$Gara['Tournament']['ToCategory']='0';
        //		$Gara['Tournament']['ToElabTeam']='0';
        //		$Gara['Tournament']['ToElimination']='0';
        //		$Gara['Tournament']['ToGolds']='';
        //		$Gara['Tournament']['ToXNine']='';
        //		$Gara['Tournament']['ToDouble']='0';
        // ora dai tipi di torneo prendo i valori di default e li metto nel vettore
        $TourTypes = array('ToTypeName' => 'Type_FITA', 'ToNumDist' => '4', 'ToNumEnds' => '12', 'ToMaxDistScore' => '360', 'ToMaxFinIndScore' => '120', 'ToMaxFinTeamScore' => '240', 'ToCategory' => '1', 'ToElabTeam' => '0', 'ToElimination' => '0', 'ToGolds' => '10', 'ToXNine' => 'X', 'ToGoldsChars' => 'L', 'ToXNineChars' => 'K', 'ToDouble' => '0');
        switch ($Gara['Tournament']['ToType']) {
            case '2':
                $TourTypes['ToTypeName'] = 'Type_2xFITA';
                $TourTypes['ToNumDist'] = '8';
                $TourTypes['ToDouble'] = '1';
                break;
            case '3':
                $TourTypes['ToTypeName'] = 'Type_70m Round';
                $TourTypes['ToNumDist'] = '2';
                break;
            case '4':
                $TourTypes['ToTypeName'] = 'Type_FITA 72';
                $TourTypes['ToNumEnds'] = '6';
                $TourTypes['ToMaxDistScore'] = '180';
                break;
            case '5':
                $TourTypes['ToTypeName'] = 'Type_900 Round';
                $TourTypes['ToNumDist'] = '3';
                $TourTypes['ToNumEnds'] = '10';
                $TourTypes['ToMaxDistScore'] = '300';
                $TourTypes['ToMaxFinIndScore'] = '0';
                $TourTypes['ToMaxFinTeamScore'] = '0';
                break;
            case '6':
                $TourTypes['ToTypeName'] = 'Type_Indoor 18';
                $TourTypes['ToNumDist'] = '2';
                $TourTypes['ToNumEnds'] = '10';
                $TourTypes['ToMaxDistScore'] = '300';
                $TourTypes['ToCategory'] = '2';
                $TourTypes['ToXNine'] = '9';
                $TourTypes['ToXNineChars'] = 'J';
                break;
            case '7':
                $TourTypes['ToTypeName'] = 'Type_Indoor 25';
                $TourTypes['ToNumDist'] = '2';
                $TourTypes['ToNumEnds'] = '10';
                $TourTypes['ToMaxDistScore'] = '300';
                $TourTypes['ToCategory'] = '2';
                $TourTypes['ToXNine'] = '9';
                $TourTypes['ToXNineChars'] = 'J';
                break;
            case '8':
                $TourTypes['ToTypeName'] = 'Type_Indoor 25+18';
                $TourTypes['ToNumEnds'] = '10';
                $TourTypes['ToMaxDistScore'] = '300';
                $TourTypes['ToCategory'] = '2';
                $TourTypes['ToXNine'] = '9';
                $TourTypes['ToXNineChars'] = 'J';
                $TourTypes['ToDouble'] = '1';
                break;
            case '9':
            case '10':
            case '12':
                $TourTypes['ToTypeName'] = $Gara['Tournament']['ToType'] == '10' ? 'Type_HF 24+24' : 'Type_HF 12+12';
                $TourTypes['ToNumDist'] = $Gara['Tournament']['ToType'] == '9' ? '1' : '2';
                $TourTypes['ToNumEnds'] = $Gara['Tournament']['ToType'] == '12' ? '12' : '24';
                $TourTypes['ToMaxDistScore'] = $Gara['Tournament']['ToType'] == '12' ? '216' : '432';
                $TourTypes['ToMaxFinIndScore'] = '72';
                $TourTypes['ToMaxFinTeamScore'] = '144';
                $TourTypes['ToCategory'] = '4';
                $TourTypes['ToElabTeam'] = '1';
                $TourTypes['ToElimination'] = '1';
                $TourTypes['ToGolds'] = '6+5';
                $TourTypes['ToXNine'] = '6';
                $TourTypes['ToGoldsChars'] = 'FG';
                $TourTypes['ToXNineChars'] = 'G';
                break;
            case '11':
            case '13':
                $TourTypes['ToTypeName'] = '3D';
                $TourTypes['ToNumDist'] = $Gara['Tournament']['ToType'] == '11' ? '1' : '2';
                $TourTypes['ToNumEnds'] = '20';
                $TourTypes['ToMaxDistScore'] = '220';
                $TourTypes['ToMaxFinIndScore'] = '44';
                $TourTypes['ToMaxFinTeamScore'] = '132';
                $TourTypes['ToCategory'] = '8';
                $TourTypes['ToElabTeam'] = '2';
                $TourTypes['ToElimination'] = '1';
                $TourTypes['ToGolds'] = '11';
                $TourTypes['ToXNine'] = '10';
                $TourTypes['ToGoldsChars'] = 'M';
                $TourTypes['ToXNineChars'] = 'L';
                break;
            case '14':
                $TourTypes['ToTypeName'] = 'Type_Las Vegas';
                $TourTypes['ToNumDist'] = '4';
                $TourTypes['ToNumEnds'] = '10';
                $TourTypes['ToMaxDistScore'] = '300';
                $TourTypes['ToMaxFinIndScore'] = '0';
                $TourTypes['ToMaxFinTeamScore'] = '0';
                break;
            case '15':
                $TourTypes['ToTypeName'] = 'Type_GiochiGioventu';
                $TourTypes['ToNumDist'] = '2';
                $TourTypes['ToNumEnds'] = '8';
                $TourTypes['ToMaxDistScore'] = '240';
                $TourTypes['ToMaxFinIndScore'] = '0';
                $TourTypes['ToMaxFinTeamScore'] = '0';
                break;
            case '16':
                $TourTypes['ToTypeName'] = 'Type_GiochiGioventuW';
                $TourTypes['ToNumDist'] = '2';
                $TourTypes['ToNumEnds'] = '8';
                $TourTypes['ToMaxDistScore'] = '240';
                $TourTypes['ToMaxFinIndScore'] = '0';
                $TourTypes['ToMaxFinTeamScore'] = '0';
                $TourTypes['ToCategory'] = '2';
                $TourTypes['ToXNine'] = '9';
                $TourTypes['ToXNineChars'] = 'J';
                break;
        }
        $Gara['Tournament'] = array_merge($Gara['Tournament'], $TourTypes);
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-09-03 17:45:00') {
        // per prima cosa tiro fuori gli eventi delle finali e delle eliminatorie con i bersagli (id)
        $events = array();
        foreach ($Gara['Events'] as $g) {
            $events[$g['EvCode']] = $g['EvFinalTargetType'];
        }
        /*print '<pre>';
        		print_r($events);*/
        /*
         * Regole di trasformazione.
         * la chiave è il tipo di target e ogni array contiene la serie di regole per
         * le sostituzioni.
         * Il giochino funziona così:
         * nelle tabelle interessate c'è la colonna dell'evento.
         * Da questo posso risalire, usando il vettore $events creato prima, al bersaglio di quell'evento.
         * Quindi ciclando dentro al vettore dei records di Finals, TeamFinals, Eliminations posso prendere la regola
         * giusta nel vettore qui sotto ed eseguire la serie di sostituzioni sui campi che a seconda saranno FinArrowstring,
         * TfArrostring etc... in base alla tabella che sto ciclando.
         */
        $rules = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 10 => array());
        // TrgIndComplete
        $rules[1] = array(array('from' => 'K', 'to' => 'L'), array('from' => 'k', 'to' => 'l'));
        // TrgIndSmall
        $rules[2] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'F', 'to' => 'A'), array('from' => 'K', 'to' => 'L'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'a'), array('from' => 'k', 'to' => 'l'));
        // TrgCOIndComplete
        $rules[3] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'F', 'to' => 'A'), array('from' => 'L', 'to' => 'J'), array('from' => 'K', 'to' => 'L'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'a'), array('from' => 'l', 'to' => 'j'), array('from' => 'k', 'to' => 'l'));
        // TrgCOIndSmall
        $rules[4] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'F', 'to' => 'A'), array('from' => 'L', 'to' => 'J'), array('from' => 'K', 'to' => 'L'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'a'), array('from' => 'l', 'to' => 'j'), array('from' => 'k', 'to' => 'l'));
        // TrgOutdoor (questo non va toccato!!!)
        $rules[5] = array();
        // TrgField
        $rules[6] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'F', 'to' => 'B'), array('from' => 'G', 'to' => 'C'), array('from' => 'H', 'to' => 'D'), array('from' => 'I', 'to' => 'E'), array('from' => 'J', 'to' => 'F'), array('from' => 'K', 'to' => 'G'), array('from' => 'L', 'to' => 'G'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'b'), array('from' => 'g', 'to' => 'c'), array('from' => 'h', 'to' => 'd'), array('from' => 'i', 'to' => 'e'), array('from' => 'j', 'to' => 'f'), array('from' => 'k', 'to' => 'g'), array('from' => 'l', 'to' => 'g'));
        // TrgHMOutComplete
        $rules[7] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'F', 'to' => 'A'), array('from' => 'G', 'to' => 'A'), array('from' => 'H', 'to' => 'A'), array('from' => 'I', 'to' => 'A'), array('from' => 'J', 'to' => 'B'), array('from' => 'K', 'to' => 'B'), array('from' => 'L', 'to' => 'B'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'a'), array('from' => 'g', 'to' => 'a'), array('from' => 'h', 'to' => 'a'), array('from' => 'i', 'to' => 'a'), array('from' => 'j', 'to' => 'b'), array('from' => 'k', 'to' => 'b'), array('from' => 'l', 'to' => 'b'));
        // Trg3DComplete
        $rules[8] = array(array('from' => 'B', 'to' => 'A'), array('from' => 'C', 'to' => 'A'), array('from' => 'D', 'to' => 'A'), array('from' => 'E', 'to' => 'A'), array('from' => 'G', 'to' => 'A'), array('from' => 'H', 'to' => 'A'), array('from' => 'J', 'to' => 'A'), array('from' => 'K', 'to' => 'M'), array('from' => 'b', 'to' => 'a'), array('from' => 'c', 'to' => 'a'), array('from' => 'd', 'to' => 'a'), array('from' => 'e', 'to' => 'a'), array('from' => 'f', 'to' => 'a'), array('from' => 'h', 'to' => 'a'), array('from' => 'j', 'to' => 'a'), array('from' => 'k', 'to' => 'm'));
        // nel db abbiamo due target Trg3DComplete
        $rules[10] = $rules[8];
        /*
         * Adesso definisco le tabelle su cui ciclare e i campi da considerare.
         * In chiave ho la tabella e ogni elemento ha la seguente struttura:
         * array(eventField,fields)
         * 		con eventField il campo da usare per scoprire l'evento per risalire al bersaglio
         * 			fields un array con i campi della tabella a cui verranno applicate le regole
         */
        $tables = array('Finals' => array('eventField' => 'FinEvent', 'fields' => array('FinArrowstring', 'FinTiebreak')), 'TeamFinals' => array('eventField' => 'TfEvent', 'fields' => array('TfArrowstring', 'TfTiebreak')), 'Eliminations' => array('eventField' => 'ElEventCode', 'fields' => array('ElArrowString')));
        // per ogni tabella definita qui sopra...
        foreach ($tables as $table => $infos) {
            // fondamentale la '&' prima di $row perchè nel ciclo più interno la variabile viene riassegnata!!!!
            foreach ($Gara[$table] as &$row) {
                /*
                 * per risalire al bersaglio della riga devo cercare in $events
                 * la chiave con l'evento corretto che si trova nella colonna  $infos['eventField']
                 * della riga attuale ($row).
                 */
                $target = $events[$row[$infos['eventField']]];
                /*print $target.'<br>';
                		print_r($rules[$target]);*/
                /*print '<pre>';
                		print_r($row);
                		print '</pre>';*/
                /*
                 * adesso ad ogni campo definito in $infos['fields'] applico le regole
                 */
                //print 'target: ' . $target . '<br>';
                foreach ($infos['fields'] as $field) {
                    //print 'prima: <b>' . $field . '</b> ' . $row[$field] . '<br>';
                    foreach ($rules[$target] as $rule) {
                        $row[$field] = str_replace($rule['from'], $rule['to'], $row[$field]);
                    }
                    //print 'dopo: <b>' . $field . '</b> ' . $row[$field] . '<br>';
                }
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-09-15 09:35:00') {
        /*print 'prima<br>';
        		print '<pre>';
        		print_r($Gara['Events']);
        		print '</pre>';*/
        /*
         * Tabella dei valori.
         * La chiave indica la terna Ind_Mode_Mixed
         * con Ind 0 o 1 se individuale o team; Mode 0 o 1 se cumulativo o set; Mixed 0 o 1 se team normale o mixed
         */
        $rules = array('0_0_0' => array('EvElimEnds' => 2, 'EvElimArrows' => 6, 'EvElimSO' => 3, 'EvFinEnds' => 4, 'EvFinArrows' => 3, 'EvFinSO' => 3), '0_1_0' => array('EvElimEnds' => 3, 'EvElimArrows' => 6, 'EvElimSO' => 1, 'EvFinEnds' => 5, 'EvFinArrows' => 3, 'EvFinSO' => 1), '1_0_0' => array('EvElimEnds' => 4, 'EvElimArrows' => 6, 'EvElimSO' => 9, 'EvFinEnds' => 4, 'EvFinArrows' => 6, 'EvFinSO' => 9), '1_0_1' => array('EvElimEnds' => 4, 'EvElimArrows' => 4, 'EvElimSO' => 6, 'EvFinEnds' => 4, 'EvFinArrows' => 4, 'EvFinSO' => 6));
        if (in_array($Gara['Tournament']['ToType'], array(9, 10, 12))) {
            // HF, one of 3 types
            $rules = array('0_0_0' => array('EvElimEnds' => 12, 'EvElimArrows' => 3, 'EvElimSO' => 3, 'EvFinEnds' => 4, 'EvFinArrows' => 3, 'EvFinSO' => 3), '1_0_0' => array('EvElimEnds' => 8, 'EvElimArrows' => 3, 'EvElimSO' => 3, 'EvFinEnds' => 4, 'EvFinArrows' => 3, 'EvFinSO' => 3));
        }
        if (in_array($Gara['Tournament']['ToType'], array(11, 13))) {
            // 3D, one of 2 types
            $rules = array('0_0_0' => array('EvElimEnds' => 12, 'EvElimArrows' => 1, 'EvElimSO' => 1, 'EvFinEnds' => 4, 'EvFinArrows' => 1, 'EvFinSO' => 1), '1_0_0' => array('EvElimEnds' => 8, 'EvElimArrows' => 3, 'EvElimSO' => 3, 'EvFinEnds' => 4, 'EvFinArrows' => 3, 'EvFinSO' => 3));
        }
        foreach ($Gara['Events'] as $k => &$v) {
            $r = $v['EvTeamEvent'] . '_' . $v['EvMatchMode'] . '_' . $v['EvMixedTeam'];
            foreach ($rules[$r] as $field => $param) {
                $v[$field] = $param;
            }
        }
        /*print 'dopo<br>';
        		print '<pre>';
        		print_r($Gara['Events']);
        		print '</pre>';
        		exit;*/
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-09-24 15:00:00') {
        // Aggiorna la FinSchedule inserendo la posizione a bersaglio
        $Events = array();
        foreach ($Gara['FinSchedule'] as $k => &$v) {
            if ($v['FSTarget']) {
                $v['FSLetter'] = $v['FSTarget'] . 'A';
                if ($v['FSMatchNo'] % 2 == 0) {
                    $tmp = $v;
                    $tmp['FSMatchNo'] = $v['FSMatchNo'] + 1;
                    $Events[] = $tmp;
                }
            }
        }
        foreach ($Gara['FinSchedule'] as $k => &$v) {
            if ($v['FSTarget'] and in_array($v, $Events)) {
                $v['FSLetter'] = $v['FSTarget'] . 'B';
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-10-12 15:44:00') {
        // aggiungo la tabella Session
        $Gara['Session'] = array();
        // ora la popolo pigliando i dati dalle colonne di Tournament
        $ToNumSession = $Gara['Tournament']['ToNumSession'];
        for ($i = 1; $i <= $ToNumSession; ++$i) {
            $Gara['Session'][] = array('SesTournament' => $Gara['Tournament']['ToId'], 'SesOrder' => $i, 'SesType' => 'Q', 'SesName' => '', 'SesTar4Session' => $Gara['Tournament']['ToTar4Session' . $i], 'SesAth4Target' => $Gara['Tournament']['ToAth4Target' . $i], 'SesFirstTarget' => 1, 'SesFollow' => 0);
        }
        /*print '<pre>';
        		print_r($Gara['Session']);
        		print '</pre>';exit;*/
        /*
         * ATTENZIONE!!!
         * Qui andrebbe la cancellazione dei vecchi campi
         *
         * ToTar4Session1,ToTar4Session2,ToTar4Session3,ToTar4Session4,ToTar4Session5,ToTar4Session6,ToTar4Session7,ToTar4Session8,ToTar4Session9,ToAth4Target1,ToAth4Target2,ToAth4Target3,ToAth4Target4,ToAth4Target5,ToAth4Target6,	ToAth4Target7,ToAth4Target8,ToAth4Target9
         *
         * da Tournament
         */
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-10-18 15:32:00') {
        // Aggiorna i targetFaces
        $Gara['TargetFaces'] = array();
        $tmp = array('TfTournament' => $Gara['Tournament']['ToId'], 'TfId' => '0', 'TfName' => '~Default', 'TfClasses' => '%', 'TfDefault' => '1', 'TfT1' => '0', 'TfW1' => '0', 'TfT2' => '0', 'TfW2' => '0', 'TfT3' => '0', 'TfW3' => '0', 'TfT4' => '0', 'TfW4' => '0', 'TfT5' => '0', 'TfW5' => '0', 'TfT6' => '0', 'TfW6' => '0', 'TfT7' => '0', 'TfW7' => '0', 'TfT8' => '0', 'TfW8' => '0');
        switch ($Gara['Tournament']['ToType']) {
            case 2:
                //	Type_2xFITA
                $Straight1 = $Gara['Tournament']['Td1'] >= $Gara['Tournament']['Td2'];
                // FITA 90-70-50-30 or 4*70m
                $Straight2 = $Gara['Tournament']['Td5'] >= $Gara['Tournament']['Td6'];
                // FITA 90-70-50-30 or 4*70m
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = '5';
                $tmp['TfW1'] = $Straight1 ? 122 : 80;
                $tmp['TfT2'] = '5';
                $tmp['TfW2'] = $Straight1 ? 122 : 80;
                $tmp['TfT3'] = '5';
                $tmp['TfW3'] = $Straight1 ? 80 : 122;
                $tmp['TfT4'] = '5';
                $tmp['TfW4'] = $Straight1 ? 80 : 122;
                $tmp['TfT5'] = '5';
                $tmp['TfW5'] = $Straight2 ? 122 : 80;
                $tmp['TfT6'] = '5';
                $tmp['TfW6'] = $Straight2 ? 122 : 80;
                $tmp['TfT7'] = '5';
                $tmp['TfW7'] = $Straight2 ? 80 : 122;
                $tmp['TfT8'] = '5';
                $tmp['TfW8'] = $Straight2 ? 80 : 122;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 2;
                $tmp['TfW1'] = $Straight1 ? 60 : 122;
                $tmp['TfW2'] = 80;
                $tmp['TfW3'] = 80;
                $tmp['TfW4'] = $Straight1 ? 122 : 60;
                $tmp['TfW5'] = $Straight2 ? 60 : 122;
                $tmp['TfW6'] = 80;
                $tmp['TfW7'] = 80;
                $tmp['TfW8'] = $Straight2 ? 122 : 60;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '2', array('VI'));
                // update VI
                break;
            case 1:
                // Type_FITA
            // Type_FITA
            case 4:
                //	Type_FITA 72
                $Straight = $Gara['Tournament']['Td1'] >= $Gara['Tournament']['Td2'];
                // FITA 90-70-50-30 or 4*70m
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = '5';
                $tmp['TfW1'] = $Straight ? 122 : 80;
                $tmp['TfT2'] = '5';
                $tmp['TfW2'] = $Straight ? 122 : 80;
                $tmp['TfT3'] = '5';
                $tmp['TfW3'] = $Straight ? 80 : 122;
                $tmp['TfT4'] = '5';
                $tmp['TfW4'] = $Straight ? 80 : 122;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 2;
                $tmp['TfW1'] = $Straight ? 60 : 122;
                $tmp['TfW2'] = 80;
                $tmp['TfW3'] = 80;
                $tmp['TfW4'] = $Straight ? 122 : 60;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '2', array('VI'));
                // update VI
                break;
            case 5:
                //	Type_900 Round
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = '5';
                $tmp['TfW1'] = 122;
                $tmp['TfT2'] = '5';
                $tmp['TfW2'] = 122;
                $tmp['TfT3'] = '5';
                $tmp['TfW3'] = 122;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
            case 3:
                //	Type_70m Round
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = '5';
                $tmp['TfW1'] = 122;
                $tmp['TfT2'] = '5';
                $tmp['TfW2'] = 122;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 2;
                $tmp['TfW1'] = 80;
                $tmp['TfW2'] = 80;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '2', array('VI'));
                // update VI
                break;
            case 8:
                //	Type_Indoor 25+18
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 60;
                $tmp['TfT3'] = 1;
                $tmp['TfW3'] = 40;
                $tmp['TfT4'] = 1;
                $tmp['TfW4'] = 40;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = 'Default COG';
                $tmp['TfClasses'] = 'COG_';
                $tmp['TfId'] = 4;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 80;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 80;
                $tmp['TfT3'] = 4;
                $tmp['TfW3'] = 60;
                $tmp['TfT4'] = 4;
                $tmp['TfW4'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // CoGio
                UpdateDivsClass($Gara, '4', array('C', 'CO', 'C1'), array('GM', 'GF'));
                // update GioCO
                $tmp['TfName'] = 'Default G';
                $tmp['TfClasses'] = '__G_';
                $tmp['TfId'] = 3;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 80;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 80;
                $tmp['TfT3'] = 1;
                $tmp['TfW3'] = 60;
                $tmp['TfT4'] = 1;
                $tmp['TfW4'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // Giovanissimi
                UpdateDivsClass($Gara, '3', array(), array('GM', 'GF'));
                // update other Gio
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 5;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '5', array('VI'));
                // update VI
                $tmp['TfName'] = '~DefaultCO';
                $tmp['TfClasses'] = 'C%';
                $tmp['TfId'] = 2;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 60;
                $tmp['TfT3'] = 4;
                $tmp['TfW3'] = 40;
                $tmp['TfT4'] = 4;
                $tmp['TfW4'] = 40;
                $Gara['TargetFaces'][] = $tmp;
                // Compounds
                UpdateDivsClass($Gara, '2', array('C', 'CO', 'C1'));
                // update Compounds
                break;
            case 7:
                //	Type_Indoor 25
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = 'Default COG';
                $tmp['TfClasses'] = 'COG_';
                $tmp['TfId'] = 4;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 80;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 80;
                $Gara['TargetFaces'][] = $tmp;
                // CoGio
                UpdateDivsClass($Gara, '4', array('C', 'CO', 'C1'), array('GM', 'GF'));
                // update GioCO
                $tmp['TfName'] = 'Default G';
                $tmp['TfClasses'] = '__G_';
                $tmp['TfId'] = 3;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 80;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 80;
                $Gara['TargetFaces'][] = $tmp;
                // Giovanissimi
                UpdateDivsClass($Gara, '3', array(), array('GM', 'GF'));
                // update other Gio
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 5;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '5', array('VI'));
                // update VI
                $tmp['TfName'] = '~DefaultCO';
                $tmp['TfClasses'] = 'C%';
                $tmp['TfId'] = 2;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // Compounds
                UpdateDivsClass($Gara, '2', array('C', 'CO', 'C1'));
                // update Compounds
                break;
            case 6:
                //	Type_Indoor 18
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 40;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 40;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = 'Default COG';
                $tmp['TfClasses'] = 'COG_';
                $tmp['TfId'] = 4;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // CoGio
                UpdateDivsClass($Gara, '4', array('C', 'CO', 'C1'), array('GM', 'GF'));
                // update GioCO
                $tmp['TfName'] = 'Default G';
                $tmp['TfClasses'] = '__G_';
                $tmp['TfId'] = 3;
                $tmp['TfT1'] = 1;
                $tmp['TfW1'] = 60;
                $tmp['TfT2'] = 1;
                $tmp['TfW2'] = 60;
                $Gara['TargetFaces'][] = $tmp;
                // Giovanissimi
                UpdateDivsClass($Gara, '3', array(), array('GM', 'GF'));
                // update other Gio
                $tmp['TfName'] = '~DefaultVI';
                $tmp['TfClasses'] = 'VI%';
                $tmp['TfId'] = 5;
                $Gara['TargetFaces'][] = $tmp;
                // VI
                UpdateDivsClass($Gara, '5', array('VI'));
                // update VI
                $tmp['TfName'] = '~DefaultCO';
                $tmp['TfClasses'] = 'C%';
                $tmp['TfId'] = 2;
                $tmp['TfT1'] = 4;
                $tmp['TfW1'] = 40;
                $tmp['TfT2'] = 4;
                $tmp['TfW2'] = 40;
                $Gara['TargetFaces'][] = $tmp;
                // Compounds
                UpdateDivsClass($Gara, '2', array('C', 'CO', 'C1'));
                // update Compounds
                break;
            case 10:
                //	Type_HF 24+24
            //	Type_HF 24+24
            case 12:
                //	Type_HF 12+12
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 6;
                $tmp['TfT2'] = 6;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
            case 9:
                //	Type_HF 12+12
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 6;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
            case 13:
                //	3D
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 8;
                $tmp['TfT2'] = 8;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
            case 11:
                //	3D
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 8;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
            case 14:
                //	Type_Las Vegas: EVERYBODY shoots on large 10 ring, CO shoot on small target
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 1;
                $tmp['TfT2'] = 1;
                $tmp['TfT3'] = 1;
                $tmp['TfT4'] = 1;
                $tmp['TfW1'] = 40;
                $tmp['TfW2'] = 40;
                $tmp['TfW3'] = 40;
                $tmp['TfW4'] = 40;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                $tmp['TfName'] = '~DefaultCO';
                $tmp['TfClasses'] = 'C%';
                $tmp['TfId'] = 2;
                $tmp['TfT1'] = 2;
                $tmp['TfT2'] = 2;
                $tmp['TfT3'] = 2;
                $tmp['TfT4'] = 2;
                $Gara['TargetFaces'][] = $tmp;
                // Compound
                UpdateDivsClass($Gara, '2', array('C', 'CO'));
                // update Compounds
                break;
            case 15:
                //	Type_GiochiGioventu
            //	Type_GiochiGioventu
            case 16:
                //	Type_GiochiGioventuWinter
                $tmp['TfId'] = 1;
                $tmp['TfT1'] = 5;
                $tmp['TfT2'] = 5;
                $tmp['TfW1'] = 80;
                $tmp['TfW2'] = 80;
                $Gara['TargetFaces'][] = $tmp;
                // Catch All
                break;
        }
        UpdateDivsClass($Gara);
        // catchall
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-10-26 11:30:00') {
        // tolgo i campi ToAth4Target[i] e ToTar4Session[i] 1<=i<=9
        for ($i = 1; $i <= 9; ++$i) {
            unset($Gara['Tournament']['ToTar4Session' . $i]);
            unset($Gara['Tournament']['ToAth4Target' . $i]);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-11-08 11:48:00') {
        /*
         * Devo aggiornare la gestione delle eliminatorie.
         *
         * Prima tiro fuori l'elenco degli eventi con le eliminatorie (in teoria tutti ma non si sa mai!)
         */
        $events = array();
        foreach ($Gara['Events'] as $e) {
            if ($e['EvElim2'] != 0) {
                $events[$e['EvCode']] = $e;
            }
        }
        // tiro fuori per ogni Qualifications l'id e la rank
        $qualifications = array();
        foreach ($Gara['Qualifications'] as $q) {
            $qualifications[$q['QuId']] = $q['QuRank'];
        }
        /*
         *  per ogni Eliminations di fase 0 tiro fuori id_fase e ElRank
         */
        $eliminations = array();
        foreach ($Gara['Eliminations'] as $g) {
            if ($g['ElElimPhase'] == 0) {
                $eliminations[$g['ElId'] . '_' . $g['ElElimPhase']] = $g['ElRank'];
            }
        }
        // Aggiungo il riferimento al torneo alle righe di Eliminations
        foreach ($Gara['Eliminations'] as &$g) {
            if (array_key_exists($g['ElEventCode'], $events)) {
                $g['ElTournament'] = $Gara['Tournament']['ToId'];
            }
        }
        /*print '<pre>';
        		print_r($events);
        		print_r($qualifications);
        		print_r($eliminations);
        		print_r($Gara['Eliminations']);
        		print '</pre>';		exit;*/
        /*
         *  Adesso metto a posto la rank.
         *  Prima le righe di Eliminations con l'evento che ha EvElim1=0
         */
        foreach ($Gara['Eliminations'] as &$g) {
            if ($events[$g['ElEventCode']]['EvElim1'] == 0) {
                $g['ElQualRank'] = $qualifications[$g['ElId']];
            }
        }
        /*
         * Adesso le righe con EvElim!=0
         */
        foreach ($Gara['Eliminations'] as &$g) {
            // due fasi
            if ($events[$g['ElEventCode']]['EvElim1'] != 0) {
                // qui piglio da $qualifications perchè sto mettendo a posto la prima fase
                if ($g['ElElimPhase'] == 0) {
                    $g['ElQualRank'] = $qualifications[$g['ElId']];
                } else {
                    $g['ElQualRank'] = $eliminations[$g['ElId'] . '_0'];
                }
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2010-12-03 17:40:00') {
        //Creo il vettore di lookup della definizione eventi
        $lookupEvents = array();
        foreach ($Gara['EventClass'] as $ecKey => $ecValue) {
            if ($ecValue['EcTeamEvent'] == 0) {
                if (array_key_exists($ecValue['EcClass'] . $ecValue['EcDivision'], $lookupEvents)) {
                    $lookupEvents[$ecValue['EcClass'] . $ecValue['EcDivision']][] = $ecValue['EcCode'];
                } else {
                    $lookupEvents[$ecValue['EcClass'] . $ecValue['EcDivision']] = array($ecValue['EcCode']);
                }
            }
        }
        foreach ($Gara['Qualifications'] as $qKey => $qValue) {
            if ($Gara['Entries'][$qValue['QuId']]['EnAthlete'] == 1) {
                if (array_key_exists($Gara['Entries'][$qValue['QuId']]['EnClass'] . $Gara['Entries'][$qValue['QuId']]['EnDivision'], $lookupEvents)) {
                    for ($i = 0; $i < count($lookupEvents[$Gara['Entries'][$qValue['QuId']]['EnClass'] . $Gara['Entries'][$qValue['QuId']]['EnDivision']]); $i++) {
                        if (!array_key_exists('Individuals', $Gara)) {
                            $Gara['Individuals'] = array();
                        }
                        $Gara['Individuals'][] = array('IndId' => $qValue['QuId'], 'IndEvent' => $lookupEvents[$Gara['Entries'][$qValue['QuId']]['EnClass'] . $Gara['Entries'][$qValue['QuId']]['EnDivision']][$i], 'IndTournament' => $Gara['Tournament']['ToId'], 'IndRank' => $qValue['QuRank'], 'IndTieBreak' => $qValue['QuTieBreak']);
                    }
                }
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-01-17 00:32:00') {
        // removes the 3 fields...
        unset($Gara['Tournament']['ToUpNamesUrl']);
        unset($Gara['Tournament']['ToUpPhotosUrl']);
        unset($Gara['Tournament']['ToUpFlagsUrl']);
        // updates the IocCode of the tournament
        if ($Gara['Tournament']['ToLocRule'] == 'IT') {
            $Gara['Tournament']['ToIocCode'] = 'ITA';
            foreach ($Gara['Entries'] as $key => $val) {
                $Gara['Entries'][$key]['EnIocCode'] = 'ITA';
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-01-30 12:56:00') {
        // Aggiorna le bandiere!!!
        if (!empty($Gara['Flags'])) {
            foreach ($Gara['Flags'] as $key => $Flag) {
                if (!empty($Flag['FlPNG'])) {
                    $tmpnam = tempnam('/tmp', 'img');
                    $img = imagecreatefromstring(base64_decode($Flag['FlPNG']));
                    imagejpeg($img, $tmpnam, 95);
                    $Gara['Flags'][$key]['FlJPG'] = base64_encode(file_get_contents($tmpnam));
                    unset($Gara['Flags'][$key]['FlPNG']);
                }
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-02-09 21:02:00') {
        foreach ($Gara['Qualifications'] as $key => $val) {
            $t = substr($val['QuTargetNo'], 0, 1) . str_pad(substr($val['QuTargetNo'], 1, -1), 3, '0', STR_PAD_LEFT) . substr($val['QuTargetNo'], -1);
            $Gara['Qualifications'][$key]['QuTargetNo'] = $t;
        }
        foreach ($Gara['AvailableTarget'] as $key => $val) {
            $t = substr($val['AtTargetNo'], 0, 1) . str_pad(substr($val['AtTargetNo'], 1, -1), 3, '0', STR_PAD_LEFT) . substr($val['AtTargetNo'], -1);
            $Gara['AvailableTarget'][$key]['AtTargetNo'] = $t;
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-02-10 11:07:00') {
        foreach ($Gara['Teams'] as $key => $val) {
            unset($Gara['Teams'][$key]["TeFinalRank"]);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-04-25 09:00:00') {
        if (array_key_exists('BroadCast', $Gara)) {
            unset($Gara['BroadCast']);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2011-08-17 18:13:00') {
        require_once 'Common/Fun_FormatText.inc.php';
        // updates Countries
        foreach ($Gara['Countries'] as $key => &$val) {
            $val['CoCode'] = mb_convert_case($val['CoCode'], MB_CASE_UPPER, "UTF-8");
            $val['CoName'] = AdjustCaseTitle($val['CoName']);
            $val['CoNameComplete'] = AdjustCaseTitle($val['CoNameComplete']);
        }
        // updates Entries
        foreach ($Gara['Entries'] as $key => &$val) {
            $val['EnName'] = AdjustCaseTitle($val['EnName']);
            $val['EnFirstName'] = AdjustCaseTitle($val['EnFirstName']);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2012-01-15 16:00:00') {
        foreach ($Gara['TVParams'] as $key => &$val) {
            $val['TVPColumns'] = 'ALL';
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2012-01-18 12:00:02') {
        if ($Gara['Tournament']['ToBlock'] == 63) {
            $Gara['Tournament']['ToBlock'] = 65535;
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2014-01-31 11:35:00') {
        foreach ($Gara['Qualifications'] as $key => $val) {
            unset($Gara['Qualifications'][$key]["QuRank"]);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2014-02-04 17:00:00') {
        foreach ($Gara['Qualifications'] as $key => $val) {
            unset($Gara['Qualifications'][$key]["QuClRankOld"]);
            unset($Gara['Qualifications'][$key]["QuSubClassRankOld"]);
            unset($Gara['Qualifications'][$key]["QuHitsCalcOld"]);
            unset($Gara['Qualifications'][$key]["QuHitsSubClassCalcOld"]);
        }
        foreach ($Gara['Individuals'] as $key => $val) {
            unset($Gara['Individuals'][$key]["IndRankOld"]);
            unset($Gara['Individuals'][$key]["IndRankCalcOld"]);
        }
        foreach ($Gara['Teams'] as $key => $val) {
            unset($Gara['Teams'][$key]["TeRankOld"]);
            unset($Gara['Teams'][$key]["TeRankCalcOld"]);
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2014-03-07 11:50:00') {
        if (!empty($Gara['DistanceInformation'])) {
            foreach ($Gara['DistanceInformation'] as $key => $row) {
                if (isset($row['DiStart'])) {
                    $Gara['DistanceInformation'][$key]['DiStartDay'] = substr($row['DiStart'], 0, 10);
                    $Gara['DistanceInformation'][$key]['DiStartTime'] = substr($row['DiStart'], -8);
                    $Gara['DistanceInformation'][$key]['DiEndDay'] = substr($row['DiEnd'], 0, 10);
                    $Gara['DistanceInformation'][$key]['DiEndTime'] = substr($row['DiEnd'], -8);
                    $Gara['DistanceInformation'][$key]['DiWarmDay'] = substr($row['DiWarmup'], 0, 10);
                    $Gara['DistanceInformation'][$key]['DiWarmTime'] = substr($row['DiWarmup'], -8);
                    unset($Gara['DistanceInformation'][$key]['DiStart']);
                    unset($Gara['DistanceInformation'][$key]['DiEnd']);
                    unset($Gara['DistanceInformation'][$key]['DiWarmup']);
                }
            }
        }
    }
    if ($Gara['Tournament']['ToDbVersion'] < '2014-05-18 19:00:01') {
        if (!empty($Gara['DistanceInformation'])) {
            foreach ($Gara['DistanceInformation'] as $key => $row) {
                $Gara['DistanceInformation'][$key]['DiDay'] = $row['DiStartDay'];
                $Gara['DistanceInformation'][$key]['DiWarmStart'] = $row['DiWarmTime'];
                $Gara['DistanceInformation'][$key]['DiStart'] = $row['DiStartTime'];
                $tmp = explode(':', $row['DiStartTime']);
                $timeStart = $tmp[0] * 60 + $tmp[1];
                $tmp = explode(':', $row['DiWarmTime']);
                $timeWarm = $tmp[0] * 60 + $tmp[1];
                $tmp = explode(':', $row['DiEndTime']);
                $timeEnd = $tmp[0] * 60 + $tmp[1];
                $Gara['DistanceInformation'][$key]['DiWarmDuration'] = $timeStart - $timeWarm;
                $Gara['DistanceInformation'][$key]['DiDuration'] = $timeEnd - $timeStart;
                unset($Gara['DistanceInformation'][$key]['DiStartDay']);
                unset($Gara['DistanceInformation'][$key]['DiStartTime']);
                unset($Gara['DistanceInformation'][$key]['DiEndDay']);
                unset($Gara['DistanceInformation'][$key]['DiEndTime']);
                unset($Gara['DistanceInformation'][$key]['DiWarmDay']);
                unset($Gara['DistanceInformation'][$key]['DiWarmTime']);
            }
        }
    }
    /*
    	if($Gara['Tournament']['ToDbVersion']<'YYYY-MM-DD HH:MM:SS') {
    		// procedura di aggiornamento della gara alla versione attuale del database
    	}
    */
    return $Gara;
}
Ejemplo n.º 5
0
}
$tourId = StrSafe_DB($_SESSION['TourId']);
$error = 0;
$coId = 0;
$coName = '#';
if (!IsBlocked(BIT_BLOCK_PARTICIPANT)) {
    if (strlen($countryCode) > 0) {
        $query = "SELECT " . "CoId, CoName " . "FROM " . "Countries " . "WHERE " . "CoCode=" . StrSafe_DB($countryCode) . " AND CoTournament=" . $tourId . " ";
        $rs = safe_r_sql($query);
        //print $query;exit;
        if ($rs) {
            // se ce ne sono di più, piglio la prima che trovo...
            if (safe_num_rows($rs) > 0) {
                $myRow = safe_fetch($rs);
                $coId = $myRow->CoId;
                $coName = AdjustCaseTitle(trim($myRow->CoName) != '' ? trim($myRow->CoName) : '#');
            }
        } else {
            $error = 1;
        }
    }
} else {
    $error = 1;
}
/****** End Controller ******/
/****** Output ******/
$xmlDoc = new DOMDocument('1.0', PageEncode);
$xmlRoot = $xmlDoc->createElement('response');
$xmlDoc->appendChild($xmlRoot);
// Header
$xmlHeader = $xmlDoc->createElement('header');
Ejemplo n.º 6
0
    if ($countryCode) {
        $query = "SELECT CoId, CoName FROM Countries WHERE CoCode=" . StrSafe_DB($countryCode) . " AND CoTournament=" . $tourId;
        $rs = safe_r_sql($query);
        if ($r = safe_fetch($rs)) {
            $countryName = $r->CoName;
        }
    }
} else {
    if ($countryName and $countryCode) {
        $query = "SELECT " . "CoId " . "FROM " . "Countries " . "WHERE " . "CoCode=" . StrSafe_DB($countryCode) . " AND CoTournament=" . $tourId . " ";
        $rs = safe_r_sql($query);
        //print $query;exit;
        if (safe_num_rows($rs) == 1) {
            $error = 0;
            $myRow = safe_fetch($rs);
            $query = "UPDATE " . "Countries " . "SET " . "CoName=" . StrSafe_DB(AdjustCaseTitle($countryName)) . " " . "WHERE " . "CoCode=" . StrSafe_DB($countryCode) . " AND CoTournament=" . $tourId . " ";
            $rs = safe_w_sql($query);
            //print $query;exit;
            if (safe_w_affected_rows()) {
                $newName = 1;
            }
        }
    }
}
/****** End Controller ******/
/****** Output ******/
$xmlDoc = new DOMDocument('1.0', PageEncode);
$xmlRoot = $xmlDoc->createElement('response');
$xmlDoc->appendChild($xmlRoot);
// Header
$xmlHeader = $xmlDoc->createElement('header');
Ejemplo n.º 7
0
     $indices = array('', 2);
 } else {
     $indices = array('');
 }
 foreach ($indices as $i) {
     $cc = StrSafe_DB($myRow->{'LueCountry' . $i});
     $query = "SELECT " . "CoId,CoName,CoNameComplete " . "FROM " . "Countries " . "WHERE " . "CoCode=" . $cc . " AND CoTournament=" . $tourId . " ";
     $rs = safe_r_sql($query);
     if ($rs) {
         $count = safe_num_rows($rs);
         switch ($count) {
             case 0:
                 // La nazione non c'è quindi la aggiungo
                 $country['CoCode'] = mb_convert_case($cc, MB_CASE_UPPER, "UTF-8");
                 $country['CoName'] = StrSafe_DB(stripslashes(AdjustCaseTitle($myRow->{'LueCoShort' . $i})));
                 $country['CoNameComplete'] = StrSafe_DB(stripslashes(AdjustCaseTitle($myRow->{'LueCoDescr' . $i})));
                 $fields = join(',', array_keys($country));
                 $values = join(',', $country);
                 $query = "INSERT INTO Countries (" . $fields . ") VALUES(" . $values . ") ";
                 $rs = safe_w_sql($query);
                 $entry['EnCountry' . $i] = safe_w_last_id();
                 break;
             case 1:
                 // La nazione esiste quindi comanda lei ma se c'è ed è senza nome, sovrascrivo quest'ultimo
                 $x = safe_fetch($rs);
                 $entry['EnCountry' . $i] = StrSafe_DB($x->CoId);
                 break;
             default:
                 // Errore
                 $error = 1;
                 break;
Ejemplo n.º 8
0
 switch ($Campo) {
     case 'EnDivision':
         $query = "SELECT EnDivision FROM Entries WHERE EnId=" . StrSafe_DB($Chiave) . " AND EnDivision<>" . StrSafe_DB($Value) . " ";
         $rs = safe_r_sql($query);
         if ($rs && safe_num_rows($rs) == 1) {
             $recalc = true;
             // prendo le vecchie impostazioni
             $x = Params4Recalc($Chiave);
             if ($x !== false) {
                 list($indFEventOld, $teamFEventOld, $countryOld, $divOld, $clOld, $zeroOld) = $x;
             }
         }
         break;
     case 'EnName':
     case 'EnFirstName':
         $Value = AdjustCaseTitle($Value);
     case 'CoName':
     case 'CoNameComplete':
         $passValue = $Value;
         break;
     case 'EnIndClEvent':
     case 'EnTeamClEvent':
     case 'EnIndFEvent':
     case 'EnTeamFEvent':
     case 'EnTeamMixEvent':
         $recalc = true;
         break;
     case 'CoParent1':
     case 'CoParent2':
         $searchSQL = "SELECT CoId FROM Countries WHERE CoCode=" . StrSafe_DB(stripslashes($Value)) . " AND CoTournament=" . StrSafe_DB($_SESSION['TourId']);
         $rsSearch = safe_r_sql($searchSQL);
Ejemplo n.º 9
0
             if (in_array($Class2Save, $tmpAgeClass)) {
                 $AgeClass2Save = $Class2Save;
             }
         }
         $SubClass2Save = $MyRow->LueSubClass;
         $Status2Save = $MyRow->LueStatus;
         // campi nazione
         $Country2Save = UpperText($MyRow->LueCountry);
         $Nation2Save = AdjustCaseTitle($MyRow->LueCoShort);
         $NationComplete2Save = AdjustCaseTitle($MyRow->LueCoDescr);
         $SecondCountry2Save = UpperText($MyRow->LueCountry2);
         $SecondNation2Save = AdjustCaseTitle($MyRow->LueCoShort2);
         $SecondNationComplete2Save = AdjustCaseTitle($MyRow->LueCoDescr2);
         $ThirdCountry2Save = UpperText($MyRow->LueCountry3);
         $ThirdNation2Save = AdjustCaseTitle($MyRow->LueCoShort3);
         $ThirdNationComplete2Save = AdjustCaseTitle($MyRow->LueCoDescr3);
     }
 }
 if (!$Division2Save or !$Class2Save) {
     $ImportResult['Refused'][] = '<tr class="error"><td>Row ' . $Line . ' missing Division or Class<br/>Row not imported</td><td>' . implode('</td><td>', $tmpString) . "</td></tr>";
     continue;
 }
 /*
 	Cerco il codice di nazione trovato nella tabella di lookup.
 Se non lo trovo, lo aggiungo con le altre info altrimenti
 prendo i dati dalla tabella delle nazioni
 */
 $TeamsFromDb = array();
 $TeamsFromDb['1'] = array('id' => '0', 'code' => $Country2Save, 'short' => $Nation2Save, 'long' => $NationComplete2Save, 'dbshort' => '', 'dblong' => '');
 $TeamsFromDb['2'] = array('id' => '0', 'code' => $SecondCountry2Save, 'short' => $SecondNation2Save, 'long' => $SecondNationComplete2Save, 'dbshort' => '', 'dblong' => '');
 $TeamsFromDb['3'] = array('id' => '0', 'code' => $ThirdCountry2Save, 'short' => $ThirdNation2Save, 'long' => $ThirdNationComplete2Save, 'dbshort' => '', 'dblong' => '');
Ejemplo n.º 10
0
function DoLookupEntries($u, $file = '')
{
    global $CFG;
    echo get_text('MsgLookup1', 'Tournament') . '<br/>';
    flush();
    //ob_flush();
    $DataSource = file_get_contents($file ? $file : $u->LupPath);
    if (!$DataSource) {
        echo "No Database<br>\n";
        return;
    }
    // checks if it is gzipped
    if ($unzipped = @gzuncompress($DataSource)) {
        $DataSource = $unzipped;
    }
    echo get_text('MsgLookup2', 'Tournament') . '<br/>';
    flush();
    // 	debug_svela($DataSource);
    //ob_flush();
    $NumRows = 0;
    if ($u->LupFors) {
        // FORS Entry
        $XML = new DOMDocument();
        $XML->preserveWhiteSpace = false;
        $XML->loadXML(trim($DataSource));
        //$XML->normalizeDocument();
        $Entries = $XML->getElementsByTagName('Table1');
        if ($Entries and $Entries->length) {
            safe_w_sql("delete from LookUpEntries where LueIocCode='{$u->LupIocCode}'");
        }
        echo get_text('MsgLookup3', 'Tournament') . '<br/>';
        @flush();
        @ob_flush();
        for ($n = 0; $n < $Entries->length; $n++) {
            $Entry = simplexml_import_dom($Entries->item($n));
            $Entry->NATIONCODE = mb_convert_case($Entry->NATIONCODE, MB_CASE_UPPER, "UTF-8");
            $Entry->SURNAME = AdjustCaseTitle($Entry->SURNAME);
            $Entry->NAME = AdjustCaseTitle($Entry->NAME);
            $Entry->NATIONDESC = AdjustCaseTitle($Entry->NATIONDESC);
            $Data = "LueFamilyName=" . StrSafe_DB($Entry->SURNAME) . "\r\n\t\t\t\t, LueName=" . StrSafe_DB($Entry->NAME) . "\r\n\t\t\t\t, LueSex=" . ($Entry->GENDER == 'M' ? 0 : 1) . "\r\n\t\t\t\t, LueCtrlCode='" . ConvertDateLoc($Entry->BIRTHDATE) . "'\r\n\t\t\t\t, LueCountry=" . StrSafe_DB($Entry->NATIONCODE) . "\r\n\t\t\t\t, LueCoDescr=" . StrSafe_DB($Entry->NATIONDESC) . "\r\n\t\t\t\t, LueDefault=1\r\n\t\t\t\t, LueCoShort=" . StrSafe_DB($Entry->NATIONDESC);
            $Sql = "insert into LookUpEntries set\r\n\t\t\t\tLueCode=" . StrSafe_DB($Entry->ID . ($Entry->TYPE == 'ATHLETE' ? '' : 'O')) . "\r\n\t\t\t\t, LueIocCode=" . StrSafe_DB($u->LupIocCode) . "\r\n\t\t\t\t, " . $Data . "\r\n\t\t\t\ton duplicate key update " . $Data;
            safe_w_sql($Sql);
            if ($NumRows++ % 100 == 0) {
                echo "- ";
            }
            if ($NumRows % 2000 == 0) {
                echo "<br>";
            }
            @flush();
            @ob_flush();
        }
        safe_w_sql("update LookUpPaths set LupLastUpdate=now() where LupIocCode='{$u->LupIocCode}'");
    } else {
        $file = $CFG->DOCUMENT_PATH . 'Tournament/TmpDownload/archers.dat';
        @file_put_contents($file, $DataSource);
        $fp = @fopen($file, 'r');
        if ($fp === false) {
            die('Cannot read downloaded data!');
        }
        // la prima riga deve essere nella forma "VERSION: #.#"
        $buffer = fgets($fp);
        if (!preg_match('/VERSION: [0-9]+\\.[0-9]+/', $buffer)) {
            die('Bad file format!');
        }
        // se la versione non è 2.0 mi fermo
        list(, $ver) = explode(':', $buffer);
        if (trim($ver) != '2.0') {
            die('Incompatible Version!');
        }
        // la seconda riga deve essere nella forma "DATE: ##############"
        $buffer = fgets($fp);
        if (!preg_match('/DATE: [0-9]{4}\\-[0-9]{2}\\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $buffer)) {
            die('Bad file format!');
        }
        $date = str_replace('DATE: ', '', $buffer);
        // la terza riga deve essere nella forma "IOC: [a-zA-Z0-9]*" e se c'è il codice lo uso come ioc
        $buffer = fgets($fp);
        $buffer = substr($buffer, 0, -1);
        // per togliere il newline finale
        if (substr($buffer, 0, 4) != 'IOC:') {
            die('Bad file format!');
        }
        $ioc = trim(str_replace('IOC:', '', $buffer));
        if (empty($ioc)) {
            $ioc = $u->LupIocCode;
        }
        // la quarta riga deve essere "CLUBS": se sì allora inizio a leggere fino a che non trovo "ENTRIES" o al più fino alla fine
        $buffer = fgets($fp);
        //print 'clubs<br>';
        if (!preg_match('/CLUBS/', $buffer)) {
            die('Bad file format!');
        }
        safe_w_sql("delete from LookUpEntries where LueIocCode='{$ioc}'");
        echo get_text('MsgLookup3', 'Tournament') . '<br/>';
        @flush();
        @ob_flush();
        $clubs = array();
        // la riga è: code nome nomebreve
        while (($buffer = fgets($fp)) !== false) {
            $buffer = substr($buffer, 0, -1);
            // per togliere il newline finale
            if ($buffer == 'ENTRIES') {
                break;
            }
            $row = explode("\t", $buffer);
            $clubs[$row[0]] = array($row[1], $row[2]);
        }
        /*
         *  qui se ho letto "ENTRIES" ho il puntatore del file già a posto. Se sono arrivato alla fine (no nomi e/o no "ENTRIES")
         *  il ciclo terminerebbe subito
         */
        // la riga è: code ioc familyname name sex dob div status validuntil soc1 soc2 terne per la classe,subcl e default
        while (($buffer = fgets($fp)) !== false) {
            $buffer = rtrim($buffer);
            // per togliere il newline finale
            $row = explode("\t", $buffer);
            // fino all'indice 10 ho dati che non riguardano la classe e dall'11 ho le terne delle classi
            $Sql = "REPLACE into LookUpEntries set " . "LueCode=" . StrSafe_DB($row[0]) . ", LueIocCode=" . StrSafe_DB($ioc) . ", LueFamilyName=" . StrSafe_DB($row[2]) . ", LueName=" . StrSafe_DB($row[3]) . ", LueSex=" . $row[4] . ", LueCtrlCode='" . $row[5] . "'" . ", LueCountry=" . StrSafe_DB($row[9]) . ", LueCoDescr=" . StrSafe_DB($clubs[$row[9]][0]) . ", LueCoShort=" . StrSafe_DB(!empty($clubs[$row[9]][1]) ? $clubs[$row[9]][1] : $clubs[$row[9]][0]) . ", LueCountry2=" . StrSafe_DB($row[10]) . ", LueCoDescr2=" . StrSafe_DB(!empty($clubs[$row[10]][0]) ? $clubs[$row[10]][0] : '') . ", LueCoShort2=" . StrSafe_DB(!empty($clubs[$row[10]][0]) ? !empty($clubs[$row[10]][1]) ? $clubs[$row[10]][1] : $clubs[$row[10]][0] : '') . ", LueDivision=" . StrSafe_DB($row[6]) . ", LueStatus=" . $row[7] . ", LueStatusValidUntil=" . StrSafe_DB($row[8]) . ", LueClass=%1\$s" . ", LueSubClass=%2\$s" . ", LueDefault=%3\$s";
            for ($i = 11; $i < count($row); $i += 3) {
                //				print $row[$i] . ' - ' . $row[$i+1] . ' - ' .$row[$i+2].'<br>';
                //				$q=sprintf($Sql, StrSafe_DB($row[$i]), StrSafe_DB($row[$i+1]), StrSafe_DB($row[$i+2]));
                //				print $q.'<br><br>';
                safe_w_sql(sprintf($Sql, StrSafe_DB($row[$i]), StrSafe_DB($row[$i + 1]), StrSafe_DB($row[$i + 2])));
            }
            if ($NumRows++ % 100 == 0) {
                echo "- ";
            }
            if ($NumRows % 2000 == 0) {
                echo "<br>";
            }
            @flush();
            @ob_flush();
        }
        fclose($fp);
        @unlink($file);
        safe_w_sql("insert into LookUpPaths set LupIocCode='{$ioc}', LupLastUpdate='{$date}' on duplicate key update LupLastUpdate='{$date}'");
    }
    echo '<br/>' . get_text('MsgLookup4', 'Tournament') . '<br/>';
    @flush();
    @ob_flush();
    // SE LA GARA NON E' BLOCCATA AGGIORNA GLI ARCIERI!
    if (!IsBlocked(BIT_BLOCK_PARTICIPANT)) {
        /*
         * Trasformazione degli stati:
         * Le righe con EnStatus=1 e LueStatus=8 con dt buona e le righe con EnStatus=6 o =7 non vengono toccate.
         * Le altre invece prendono lo status della lookup se la dt gara è precedente alla scandenza della persona altrimenti pigliano 5
         *
         */
        $Sql = "\r\n\t\t\t\tUPDATE\r\n\t\t\t\t\tEntries\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tTournament\r\n\t\t\t\t\tON EnTournament=ToId\r\n\t\t\t\t\tINNER JOIN\r\n\t\t\t\t\t\tLookUpEntries\r\n\t\t\t\t\tON EnCode=LueCode and LueIocCode=IF(EnIocCode!='',EnIocCode,ToIocCode)\r\n\t\t\t\tSET\r\n\t\t\t\t\tEnStatus=IF(ToWhenFrom>LueStatusValidUntil AND LueStatusValidUntil<>'0000-00-00',5,LueStatus)\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tEnTournament=" . StrSafe_DB($_SESSION['TourId']) . "\r\n\t\t\t\t\tAND  NOT (EnStatus=6 OR EnStatus=7 OR (EnStatus<=1 AND LueStatus=8 AND LueStatusValidUntil>=ToWhenTo AND LueStatusValidUntil<>'0000-00-00'))\r\n\t\t\t";
        $Rs = safe_w_sql($Sql);
        $Sql = "UPDATE Entries " . "INNER JOIN Tournament ON EnTournament=ToId " . "INNER JOIN LookUpEntries ON EnCode=LueCode and LueIocCode=IF(EnIocCode!='',EnIocCode,ToIocCode) AND EnClass=LueClass " . "SET EnSubClass=LueSubClass " . "WHERE EnTournament = " . StrSafe_DB($_SESSION['TourId']);
        $Rs = safe_w_sql($Sql);
        echo get_text('MsgLookup5', 'Tournament') . '<br/>';
    }
    @flush();
    @ob_flush();
    //			$Rs=safe_w_sql("LOAD DATA LOCAL INFILE '" . $CFG->DOCUMENT_PATH . "Tournament/TmpDownload/ImportData' INTO TABLE LookUpEntries");
}
Ejemplo n.º 11
0
    }
    $Sql = "select * from Countries where (binary CoNameComplete=upper(CoNameComplete) or binary CoNameComplete=upper(CoNameComplete)) and CoNameComplete>''";
    $q = safe_r_sql($Sql);
    while ($r = safe_fetch($q)) {
        safe_w_sql("update Countries set " . "CoNameComplete=" . StrSafe_DB(AdjustCaseTitle($r->CoNameComplete)) . " WHERE CoId={$r->CoId}");
    }
    // updates Entries
    $Sql = "select * from Entries where (binary EnName=upper(EnName) or binary EnName=upper(EnName)) and EnName>''";
    $q = safe_r_sql($Sql);
    while ($r = safe_fetch($q)) {
        safe_w_sql("update Entries set " . "EnName=" . StrSafe_DB(AdjustCaseTitle($r->EnName)) . " WHERE EnId={$r->EnId}");
    }
    $Sql = "select * from Entries where (binary EnFirstName=upper(EnFirstName) or binary EnFirstName=upper(EnFirstName) ) and EnFirstName>''";
    $q = safe_r_sql($Sql);
    while ($r = safe_fetch($q)) {
        safe_w_sql("update Entries set " . "EnFirstName=" . StrSafe_DB(AdjustCaseTitle($r->EnFirstName)) . " WHERE EnId={$r->EnId}");
    }
    db_save_version('2011-08-17 18:13:00');
}
if ($version < '2011-08-23 15:59:00') {
    $q = "ALTER TABLE `LookUpEntries` ADD `LueStatusValidUntil` DATE NOT NULL DEFAULT '0000-00-00' AFTER `LueStatus` ";
    $r = safe_w_sql($q, false, array(1060));
    db_save_version('2011-08-23 15:59:00');
}
if ($version < '2011-09-06 09:48:00') {
    safe_w_sql('DROP TABLE IF EXISTS `LookUpEntries`');
    safe_w_sql('CREATE TABLE IF NOT EXISTS `LookUpEntries` (
  `LueCode` varchar(9) NOT NULL,
  `LueIocCode` varchar(5) NOT NULL DEFAULT \'\',
  `LueFamilyName` varchar(60) NOT NULL,
  `LueName` varchar(30) NOT NULL,