Example #1
0
     // controlla che tutti gli spareggi siano stati fatti
     $TrueRank = 1;
     foreach ($EnIds as $EnId => $AssignedRank) {
         //print $EnId . ' - ' . $AssignedRank . ' - ' . $TrueRank.'<br>';
         if ($AssignedRank != $TrueRank && $AssignedRank <= $MaxRank[$Event]) {
             $NotResolved[$Event] = true;
         }
         $TrueRank++;
     }
     // assegna le rank SOLO se tutto è a posto
     if (!$NotResolved[$Event]) {
         foreach ($EnIds as $EnId => $AssignedRank) {
             $x = $rank->setRow(array(array('ath' => $EnId, 'event' => $Event, 'dist' => 0, 'rank' => $AssignedRank)));
             //print $EnId .' - ' . $x.' - ' . $AssignedRank . '<br>';
             if ($x == 1) {
                 $IdAffected[] = strsafe_db($EnId);
             }
         }
     } else {
         $NotResolvedMsg[] = $Event;
     }
 }
 //exit;
 // penso ai tiebreak
 foreach ($_REQUEST['T'] as $EventKey => $Event) {
     foreach ($Event as $id => $TieArrows) {
         foreach ($TieArrows as $index => $Value) {
             if (!array_key_exists($EventKey . '_' . $id, $Ties)) {
                 $Ties[$EventKey . '_' . $id] = str_pad('', 3, ' ');
             }
             $v = GetLetterFromPrint($Value);
Example #2
0
function tour_import($filename)
{
    // Tabelle che hanno il codice Tournament
    $tabs_on_tour = array('AccColors' => 'Ac', 'AccEntries' => 'AE', 'AccPrice' => 'AP', 'ACL' => 'Acl', 'AclDetails' => 'AclDt', 'AvailableTarget' => 'At', 'Awards' => 'Aw', 'Awarded' => 'Aw', 'BackNumber' => 'Bn', 'CasScore' => 'CaS', 'CasTeam' => 'Ca', 'CasTeamFinal' => 'CTF', 'CasTeamTarget' => 'CTT', 'Classes' => 'Cl', 'ClubTeam' => 'CT', 'ClubTeamScore' => 'CTS', 'Countries' => 'Co', 'Divisions' => 'Div', 'DistanceInformation' => 'Di', 'Emails' => 'Em', 'Entries' => 'En', 'EventClass' => 'Ec', 'Events' => 'Ev', 'Individuals' => 'Ind', "F2FGrid" => 'F2F', "F2FEntries" => "F2F", "F2FFinal" => "F2F", 'FinalReportA' => 'Fra', 'Finals' => 'Fin', 'FinSchedule' => 'FS', 'FinTraining' => 'Ft', 'FinTrainingEvent' => 'Fte', 'FinWarmup' => 'Fw', 'HhtData' => 'Hd', 'HhtEvents' => 'He', 'HhtSetup' => 'Hs', 'IdCardElements' => 'Ice', 'IdCards' => 'Ic', 'Images' => 'Im', 'ModulesParameters' => 'Mp', 'RecTournament' => 'Rt', 'Reviews' => 'Rev', 'SubClass' => 'Sc', 'TargetFaces' => 'Tf', 'TeamComponent' => 'Tc', 'TeamFinals' => 'Tf', 'TeamFinComponent' => 'Tfc', 'Teams' => 'Te', 'TournamentDistances' => 'Td', 'TournamentInvolved' => 'Ti', 'TourRecords' => 'Tr', 'TVContents' => 'TVC', 'TVOut' => 'TV', 'TVParams' => 'TVP', 'TVRules' => 'TVR', 'TVSequence' => 'TVS', 'Session' => 'Ses', 'Scheduler' => 'Sch', 'Eliminations' => 'El', 'VegasAwards' => 'Va');
    // Tabelle che hanno il codice Countries
    $tab_to_country = array('CasTeam' => 'CaTeam', 'ClubTeam' => 'CTTeam', 'Entries' => array('EnCountry', 'EnCountry2', 'EnCountry3'), 'TeamComponent' => 'TcCoId', 'TeamFinals' => 'TfTeam', 'TeamFinComponent' => 'TfcCoId', 'Teams' => 'TeCoId');
    // Tabelle che hanno il codice Entries
    $tab_to_entry = array('AccEntries' => 'AEId', 'Awarded' => 'AwEntry', 'ElabQualifications' => 'EqId', 'Eliminations' => 'ElId', 'ExtraData' => 'EdId', 'Individuals' => 'IndId', "F2FEntries" => "F2FEnId", "F2FFinal" => "F2FEnId", 'Finals' => 'FinAthlete', 'HhtData' => 'HdEnId', 'Photos' => 'PhEnId', 'Qualifications' => 'QuId', 'TeamComponent' => 'TcId', 'TeamFinComponent' => 'TfcId', 'Vegas' => 'VeId');
    // Tabelle che dipendono SOLO da Tournament
    $tabs_only_tour = array('AccColors', 'AccPrice', 'ACL', 'AclDetails', 'AvailableTarget', 'Awards', 'BackNumber', 'CasScore', 'CasTeamFinal', 'CasTeamTarget', 'Classes', 'ClubTeamScore', 'DistanceInformation', 'Divisions', 'Emails', 'EventClass', 'Events', 'F2FGrid', 'FinalReportA', 'FinSchedule', 'FinTraining', 'FinTrainingEvent', 'FinWarmup', 'HhtEvents', 'HhtSetup', 'IdCardElements', 'IdCards', 'Images', 'ModulesParameters', 'RecTournament', 'Reviews', 'SubClass', 'TargetFaces', 'TournamentDistances', 'TournamentInvolved', 'TourRecords', 'TVContents', 'TVOut', 'TVParams', 'TVRules', 'TVSequence', 'Session', 'Scheduler', 'Eliminations', 'VegasAwards');
    $Gara = unserialize(gzuncompress(implode('', file($filename))));
    // If is not compatible, exits
    if ($Gara['Tournament']['ToDbVersion'] > GetParameter('DBUpdate')) {
        return false;
    }
    require_once 'UpdateTournament.inc.php';
    $Gara = UpdateTournament($Gara);
    // CONTROLLA SE C'E' UN TORNEO CON LO STESSO CODICE E LO SEGA!
    $q = safe_r_sql("select ToId from Tournament where ToCode=" . strsafe_db($Gara['Tournament']['ToCode']));
    if ($r = safe_fetch($q)) {
        // esiste un tournament con lo stesso codice... ranzo tutto!
        tour_delete($r->ToId);
    }
    // Inserisce il torneo
    $quer = array();
    foreach ($Gara['Tournament'] as $key => $val) {
        if ($key != 'ToId') {
            $quer[] = "{$key}=" . strsafe_db($val);
            // 			if($key=='ToImgL') debug_svela(array('SAFE' => strsafe_db($val), '','','','','', 'ORG' => $val));
        }
    }
    safe_w_sql("Insert into Tournament set " . implode(', ', $quer));
    $TourId = safe_w_last_id();
    if (debug) {
        echo "Inserito Tournament<br />";
    }
    // aggiusta il nuovo valore del torneo nell'array...
    foreach ($tabs_on_tour as $tab => $code) {
        if (isset($Gara[$tab])) {
            foreach ($Gara[$tab] as $key => $val) {
                $Gara[$tab][$key][$code . 'Tournament'] = $TourId;
            }
            if (debug) {
                echo "Aggiornato Tournament Nr. in tabella {$tab}<br />";
            }
        }
    }
    // inserisce le tabelle che hanno SOLO il tournament
    foreach ($tabs_only_tour as $tab) {
        if (isset($Gara[$tab])) {
            foreach ($Gara[$tab] as $record) {
                $query = array();
                foreach ($record as $key => $val) {
                    $query[] = "{$key} = " . strsafe_db($val);
                }
                safe_w_sql("insert into {$tab} set " . implode(', ', $query) . " on duplicate key update " . implode(', ', $query));
            }
        }
        if (debug) {
            echo "Inserita tabella {$tab}<br />";
        }
    }
    // inserisce i paesi e mantieni l'array per il cambio country
    $Countries = array();
    if (array_key_exists('Countries', $Gara) && is_array($Gara['Countries']) && count($Gara['Countries']) > 0) {
        foreach ($Gara['Countries'] as $record) {
            $query = array();
            foreach ($record as $key => $val) {
                if ($key != 'CoId') {
                    $query[] = "{$key} = " . strsafe_db($val);
                }
            }
            safe_w_sql("insert into Countries set " . implode(', ', $query));
            $Countries[$record['CoId']] = safe_w_last_id();
        }
        if (debug) {
            echo "Inserita tabella Countries<br />";
        }
    }
    //aggiorna CoParent1 della Countries stessa
    $tmpSql = "SELECT DISTINCT CoParent1 FROM Countries WHERE CoTournament=" . $TourId . " AND CoParent1!=0";
    $tmpRs = safe_r_sql($tmpSql);
    if (safe_num_rows($tmpRs) != 0) {
        while ($tmpRow = safe_fetch($tmpRs)) {
            safe_w_sql("UPDATE Countries SET CoParent1=" . $Countries[$tmpRow->CoParent1] . " WHERE CoParent1=" . $tmpRow->CoParent1 . " AND CoTournament=" . $TourId);
        }
        safe_free_result($tmpRs);
    }
    //aggiorna CoParent2 della Countries stessa
    $tmpSql = "SELECT DISTINCT CoParent2 FROM Countries WHERE CoTournament=" . $TourId . " AND CoParent2!=0";
    $tmpRs = safe_r_sql($tmpSql);
    if (safe_num_rows($tmpRs) != 0) {
        while ($tmpRow = safe_fetch($tmpRs)) {
            safe_w_sql("UPDATE Countries SET CoParent2=" . $Countries[$tmpRow->CoParent2] . " WHERE CoParent2=" . $tmpRow->CoParent2 . " AND CoTournament=" . $TourId);
        }
        safe_free_result($tmpRs);
    }
    // aggiorna i paesi nelle tabelle che ne fanno uso
    foreach ($tab_to_country as $tab => $field) {
        if (array_key_exists($tab, $Gara)) {
            foreach ($Gara[$tab] as $key => $record) {
                if (is_array($field)) {
                    foreach ($field as $ff) {
                        if (array_key_exists($ff, $record) && $record[$ff]) {
                            $Gara[$tab][$key][$ff] = $Countries[$record[$ff]];
                        }
                    }
                } else {
                    if ($record[$field] && array_key_exists($record[$field], $Countries)) {
                        $Gara[$tab][$key][$field] = $Countries[$record[$field]];
                    }
                }
            }
        }
        if (debug) {
            echo "Aggiornata il Country di tabella {$tab}<br />";
        }
    }
    // inserisce le Entries e mantieni l'array per il cambio Entry
    $Entries = array();
    if (array_key_exists('Entries', $Gara) && is_array($Gara['Entries']) && count($Gara['Entries']) > 0) {
        foreach ($Gara['Entries'] as $record) {
            $query = array();
            foreach ($record as $key => $val) {
                if ($key != 'EnId') {
                    $query[] = "{$key} = " . strsafe_db($val);
                }
            }
            safe_w_sql("insert into Entries set " . implode(', ', $query));
            $Entries[$record['EnId']] = safe_w_last_id();
        }
        if (debug) {
            echo "Inserita tabella Entries<br />";
        }
    }
    // aggiorna le rimanenti tabelle con le Entries corrette
    foreach ($tab_to_entry as $tab => $field) {
        if (array_key_exists($tab, $Gara)) {
            foreach ($Gara[$tab] as $key => $record) {
                if (array_key_exists($record[$field], $Entries) && $record[$field]) {
                    $Gara[$tab][$key][$field] = $Entries[$record[$field]];
                }
            }
        }
        if (debug) {
            echo "Aggiornata l'Entry di tabella {$tab}<br />";
        }
    }
    // inserisce le tabelle restanti
    unset($tab_to_country['Entries']);
    $final_tabs = array_unique(array_merge(array_keys($tab_to_country), array_keys($tab_to_entry)));
    foreach ($final_tabs as $tab) {
        if (array_key_exists($tab, $Gara)) {
            foreach ($Gara[$tab] as $record) {
                $query = array();
                foreach ($record as $key => $val) {
                    $query[] = "{$key} = " . strsafe_db($val);
                }
                // attenzione: questa query era "commentata" per non far apparirer errori:
                // se questo comportamento è desiderato, chiamare la funzione safe_w_sql passando
                // come terzo parametro un array con gli errori numerici ammessi
                safe_w_sql("REPLACE INTO {$tab} set " . implode(', ', $query));
            }
        }
        if (debug) {
            echo "Inserita tabella {$tab}<br />";
        }
    }
    //Gestisce la tabella Flags
    if (array_key_exists('Flags', $Gara) && is_array($Gara['Flags']) && count($Gara['Flags']) > 0) {
        foreach ($Gara['Flags'] as $record) {
            if ($record['FlTournament'] != -1) {
                $record['FlTournament'] = $TourId;
            }
            $query = array();
            foreach ($record as $key => $val) {
                $query[] = "{$key} = " . strsafe_db($val);
            }
            safe_w_sql("insert into Flags set " . implode(', ', $query) . " on duplicate key update " . implode(', ', $query));
        }
        if (debug) {
            echo "Inserita tabella Flags<br />";
        }
    }
    return $TourId;
}
Example #3
0
     unset($_GET['ChainId']);
     cd_redirect(go_get(array('NewDb' => '', 'NewMm' => ''), true));
 }
 // Check if a new MM content has been Uploaded/Inserted
 if (!empty($_POST['d_TVContentName']) and (!empty($_POST['d_TVContentText']) or !empty($_FILES['d_TVContentUpload']['name']))) {
     $content = array();
     $content[] = "TVCTournament=" . $TourId;
     if (!empty($_POST['d_TVContentText'])) {
         $content[] = "TVCContent=" . strsafe_DB($_POST['d_TVContentText']);
         $content[] = "TVCMimeType='text/html'";
     } else {
         $content[] = "TVCContent=" . strsafe_DB(file_get_contents($_FILES['d_TVContentUpload']['tmp_name']));
         $content[] = "TVCMimeType=" . strsafe_db($_FILES['d_TVContentUpload']['type']);
     }
     $content[] = "TVCTime=" . intval($_POST['d_TVDefaultTime']);
     $content[] = "TVCName=" . strsafe_db($_POST['d_TVContentName']);
     $content[] = "TVCScroll=" . intval($_POST['d_TVDefaultScroll']);
     $q = safe_r_sql("SELECT IFNULL(MAX(TVCId),0) AS CurID FROM TVContents WHERE TVCTournament={$TourId}");
     $_POST['d_TVMultimedia'] = safe_fetch($q)->CurID + 1 . '|1';
     safe_w_sql("INSERT INTO TVContents set TVCId=" . $_POST['d_TVMultimedia'] . ", " . implode(',', $content));
     $_POST['d_TVMultimediaTime'] = intval($_POST['d_TVDefaultTime']);
     $_POST['d_TVMultimediaScroll'] = intval($_POST['d_TVDefaultScroll']);
     include_once 'Common/CheckPictures.php';
     CheckPictures();
 } elseif (!empty($_POST['d_TVMultimedia']) and !empty($_POST['d_TVContentText'])) {
     // check if a Multimedia Text has been edited in a textual context (text/html)
     // and in the current Tournament
     list($mulId, $mulTour) = explode("|", $_POST['d_TVMultimedia']);
     $q = safe_r_sql("select * from TVContents where TVCId={$mulId} AND TVCTournament=" . ($mulTour == 1 ? $TourId : "-1"));
     if ($r = safe_fetch($q) and $r->TVCMimeType == 'text/html' and $mulTour) {
         $content = array();
Example #4
0
     asort($CoIds);
     // controlla che tutti gli spareggi siano stati fatti
     $TrueRank = 1;
     foreach ($CoIds as $CoId => $AssignedRank) {
         if ($AssignedRank != $TrueRank && $AssignedRank <= $MaxRank) {
             $NotResolved[$Event] = true;
         }
         $TrueRank++;
     }
     // assegna le rank SOLO se tutto è a posto
     if (!$NotResolved[$Event]) {
         foreach ($CoIds as $CoId => $AssignedRank) {
             list($id, $subteam) = explode('_', $CoId);
             $x = $rank->setRow(array(array('team' => $id, 'subteam' => $subteam, 'event' => $Event, 'rank' => $AssignedRank)));
             if ($x == 1) {
                 $IdAffected[] = strsafe_db($CoId);
             }
         }
     } else {
         $NotResolvedMsg[] = $Event;
     }
 }
 // tie
 foreach ($_REQUEST['T'] as $EventKey => $Event) {
     foreach ($Event as $id => $TieArrows) {
         foreach ($TieArrows as $index => $Value) {
             if (!array_key_exists($EventKey . '_' . $id, $Ties)) {
                 $Ties[$EventKey . '_' . $id] = str_pad('', 3, ' ');
             }
             $v = GetLetterFromPrint($Value);
             $Ties[$EventKey . '_' . $id] = substr_replace($Ties[$EventKey . '_' . $id], $v, $index, 1);