$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); 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; } }
$DoChanges = isset($_REQUEST['TourReset']); // check rules of the tournament if (!$DoChanges and !isset($_REQUEST['New'])) { $t = safe_r_sql("select ToType, ToLocRule, ToTypeSubRule from Tournament where ToId={$_SESSION['TourId']}"); $u = safe_fetch($t); $DoChanges = ($u->ToType != $_REQUEST['d_ToType'] or $u->ToLocRule != $_REQUEST['d_Rule'] or $u->ToTypeSubRule != $ToTypeSubRule); } $ToCode = preg_replace('/[^0-9a-z.,:;_-]/sim', '', $_REQUEST['d_ToCode']); $Insert = "INSERT INTO Tournament (" . (!isset($_REQUEST['New']) ? 'ToId,' : '') . "ToType," . "ToCode," . "ToName," . "ToIocCode," . "ToCommitee," . "ToComDescr," . "ToWhere," . "ToWhenFrom," . "ToWhenTo," . "ToCurrency," . "ToPrintLang," . "ToPrintChars," . "ToPrintPaper," . "ToUseHHT," . "ToDbVersion," . "ToTypeSubRule," . "ToLocRule," . "ToIsORIS" . ") " . "VALUES(" . (!isset($_REQUEST['New']) ? StrSafe_DB($_SESSION['TourId']) . "," : '') . StrSafe_DB($_REQUEST['d_ToType']) . "," . StrSafe_DB($ToCode) . "," . StrSafe_DB(stripslashes($_REQUEST['d_ToName'])) . "," . StrSafe_DB(stripslashes($_REQUEST['d_ToIocCode'])) . "," . StrSafe_DB($_REQUEST['d_ToCommitee']) . "," . StrSafe_DB(stripslashes($_REQUEST['d_ToComDescr'])) . "," . StrSafe_DB(stripslashes($_REQUEST['d_ToWhere'])) . "," . StrSafe_DB(sprintf("%04d-%02d-%02d", intval($_REQUEST['xx_ToWhenFromYear']), intval($_REQUEST['xx_ToWhenFromMonth']), intval($_REQUEST['xx_ToWhenFromDay']))) . "," . StrSafe_DB(sprintf("%04d-%02d-%02d", intval($_REQUEST['xx_ToWhenToYear']), intval($_REQUEST['xx_ToWhenToMonth']), intval($_REQUEST['xx_ToWhenToDay']))) . "," . StrSafe_DB($_REQUEST['xx_ToCurrency']) . "," . StrSafe_DB($_REQUEST['xx_ToPrintLang']) . "," . StrSafe_DB($_REQUEST['xx_ToPrintChars']) . "," . StrSafe_DB(intval($_REQUEST['xx_ToPaperSize'])) . "," . StrSafe_DB(intval($_REQUEST['xx_ToUseHHT'])) . "," . StrSafe_DB(GetParameter('DBUpdate')) . "," . StrSafe_DB($ToTypeSubRule) . "," . StrSafe_DB($_REQUEST['d_Rule']) . "," . StrSafe_DB(!empty($_REQUEST['d_ORIS'])) . "" . ") " . "ON DUPLICATE KEY UPDATE " . "ToType = " . StrSafe_DB($_REQUEST['d_ToType']) . "," . "ToCode = " . StrSafe_DB($ToCode) . "," . "ToName = " . StrSafe_DB(stripslashes($_REQUEST['d_ToName'])) . "," . "ToIocCode = " . StrSafe_DB(stripslashes($_REQUEST['d_ToIocCode'])) . "," . "ToCommitee = " . StrSafe_DB($_REQUEST['d_ToCommitee']) . "," . "ToComDescr = " . StrSafe_DB(stripslashes($_REQUEST['d_ToComDescr'])) . "," . "ToWhere = " . StrSafe_DB(stripslashes($_REQUEST['d_ToWhere'])) . "," . "ToWhenFrom = " . StrSafe_DB(sprintf("%04d-%02d-%02d", intval($_REQUEST['xx_ToWhenFromYear']), intval($_REQUEST['xx_ToWhenFromMonth']), intval($_REQUEST['xx_ToWhenFromDay']))) . "," . "ToWhenTo = " . StrSafe_DB(sprintf("%04d-%02d-%02d", intval($_REQUEST['xx_ToWhenToYear']), intval($_REQUEST['xx_ToWhenToMonth']), intval($_REQUEST['xx_ToWhenToDay']))) . " " . "," . "ToCurrency = " . StrSafe_DB($_REQUEST['xx_ToCurrency']) . " " . "," . "ToPrintLang = " . StrSafe_DB($_REQUEST['xx_ToPrintLang']) . " " . "," . "ToPrintChars = " . StrSafe_DB($_REQUEST['xx_ToPrintChars']) . " " . "," . "ToPrintPaper = " . intval($_REQUEST['xx_ToPaperSize']) . "," . "ToUseHHT = " . intval($_REQUEST['xx_ToUseHHT']) . ", " . "ToDbVersion = " . StrSafe_DB(GetParameter('DBUpdate')) . ", " . "ToTypeSubRule = " . StrSafe_DB($ToTypeSubRule) . ", " . "ToLocRule=" . StrSafe_DB($_REQUEST['d_Rule']) . ", " . "ToIsORIS=" . StrSafe_DB(!empty($_REQUEST['d_ORIS'])) . ""; $Rs = safe_w_sql($Insert); set_qual_session_flags(); $_SESSION['ISORIS'] = !empty($_REQUEST['d_ORIS']); //print $Insert;exit; if (isset($_REQUEST['New'])) { // Recupero l'ultimo id inserito $RowId = safe_w_last_id(); if ($RowId) { $_SESSION['TourId'] = $RowId; } else { print get_text('UnexpectedError'); exit; } } if (isset($_REQUEST['New']) or $DoChanges) { //First I decide whenever, in case of new rules, I need to apply the old ones (to manage the switch on 1st April 2014) $useOldRules = intval($_REQUEST['xx_ToWhenFromYear']) < 2014 || intval($_REQUEST['xx_ToWhenFromMonth']) < 4; // Eseguo il/i file(s) di setup della gara GetSetupFile($_SESSION['TourId'], $_REQUEST['d_ToType'], $_REQUEST['d_Rule'], empty($_REQUEST['d_SubRule']) ? '1' : $_REQUEST['d_SubRule'], $useOldRules); // calcolo il numero massimo di persone in ogni team calcMaxTeamPerson(array(), true, $_SESSION['TourId']); unset($_REQUEST['New']);
$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>'; } $Update = "UPDATE Qualifications SET " . "QuSession=" . StrSafe_DB($_REQUEST['d_q_QuSession_']) . ", " . "QuTargetNo=" . StrSafe_DB(($_REQUEST['d_q_QuSession_'] != 0 ? $_REQUEST['d_q_QuSession_'] : '') . $_REQUEST['d_q_QuTargetNo_']) . " " . "WHERE QuId=" . StrSafe_DB($id) . " "; $Rs = safe_w_sql($Update); if (safe_w_affected_rows()) { safe_w_sql("update Qualifications SET QuBacknoPrinted=0 where QuId={$id}");
print get_text('CrackError'); exit; } $error = 0; if (!IsBlocked(BIT_BLOCK_PARTICIPANT)) { $tourId = StrSafe_DB($_SESSION['TourId']); $t = safe_r_sql("select NULLIF(ToIocCode,'') as nocCode from Tournament WHERE ToId={$_SESSION['TourId']}"); $u = safe_fetch($t); $nocCode = $u->nocCode; // aggiungo la riga in Entries $query = "INSERT INTO Entries (EnTournament,EnIocCode,EnDivision,EnClass,EnSubClass,EnAgeClass,EnCountry,EnCtrlCode,EnCode,EnName,EnFirstName,EnAthlete,EnSex,EnWChair,EnSitting,EnIndClEvent,EnTeamClEvent,EnIndFEvent,EnTeamFEvent,EnStatus) " . "VALUES(" . $tourId . "," . "'{$nocCode}'," . "'--'," . "'--'," . "'00'," . "'--'," . "'0'," . "''," . "''," . "''," . "''," . "'1'," . "'0'," . "'0'," . "'0'," . "'1'," . "'1'," . "'1'," . "'1'," . "'0'" . ") "; $rs = safe_w_sql($query); $newId = 0; if (safe_w_affected_rows() == 1) { // Aggiungo la riga a Qualifications $newId = safe_w_last_id(); $query = "INSERT INTO Qualifications (QuId,QuSession) " . "VALUES(" . StrSafe_DB($newId) . "," . "0" . ") "; $rs = safe_w_sql($query); } 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');
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; }
$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; } } else { $error = 1; break; }
$ImportResult['Blocked'][] = '<tr><td><a href="#" onclick="window.open(\'./ForceUpdate.php?EnId=' . $r->EnId . '&EnCo1=' . $TeamsFromDb['1']['id'] . '&EnCo2=' . $TeamsFromDb['2']['id'] . '&EnCo3=' . $TeamsFromDb['3']['id'] . '\')"" target="ForceUpdate">Force Update</a></td><td>' . implode('</td><td>', $tmpString) . "</td></tr>"; } else { $ImportResult['Unchanged']++; } continue; // goes to the next line to import } } $ImportResult['Imported']++; // Inserts the entry, so check the inital SQL adn adds the teams if (!$TeamUpdate) { $EntrySQL .= ", EnCountry={$TeamsFromDb['1']['id']}\r\n\t\t\t\t\t, EnCountry2={$TeamsFromDb['2']['id']}\r\n\t\t\t\t\t, EnCountry3={$TeamsFromDb['3']['id']}\r\n\t\t\t\t\t"; } $Insert = "INSERT INTO Entries set {$EntrySQL}"; $Rs = safe_w_sql($Insert); $idNewRow = safe_w_last_id(); // aggiungo la riga in Qualifications $Insert = "INSERT INTO Qualifications (QuId,QuSession,QuTargetNo) " . "VALUES(" . StrSafe_DB($idNewRow) . "," . StrSafe_DB($Session2Save) . "," . StrSafe_DB($Target2Save) . ") "; $Rs = safe_w_sql($Insert); $ImportResult['Inserted'][] = "<tr><td>OK</td>\n\t\t\t\t<td>{$Code2Save}</td>\n\t\t\t\t<td>{$Session2Save}</td>\n\t\t\t\t<td>{$Division2Save}</td>\n\t\t\t\t<td>{$Class2Save}</td>\n\t\t\t\t<td>{$Target2Save}</td>\n\t\t\t\t<td>{$ShootInd2Save}</td>\n\t\t\t\t<td>{$ShootTeam2Save}</td>\n\t\t\t\t<td>{$ShootFinInd2Save}</td>\n\t\t\t\t<td>{$ShootFinTeam2Save}</td>\n\t\t\t\t<td>{$ShootFinMixTeam2Save}</td>\n\t\t\t\t<td>{$FirstName2Save}</td>\n\t\t\t\t<td>{$Name2Save}</td>\n\t\t\t\t<td>{$Sex2Save}</td>\n\t\t\t\t<td>{$TeamsFromDb['1']['code']}</td>\n\t\t\t\t<td>{$TeamsFromDb['1']['short']}</td>\n\t\t\t\t<td>{$DoB2Save}</td>\n\t\t\t\t<td>{$SubClass2Save}</td>\n\t\t\t\t<td>{$TeamsFromDb['2']['code']}</td>\n\t\t\t\t<td>{$TeamsFromDb['2']['short']}</td>\n\t\t\t\t<td>{$TeamsFromDb['3']['code']}</td>\n\t\t\t\t<td>{$TeamsFromDb['3']['short']}</td></tr>"; } // updates the Athlete status in Entries safe_w_sql("update Entries left join Divisions on EnDivision=DivId and EnTournament=DivTournament left join Classes on EnClass=ClId and EnTournament=ClTournament set EnAthlete=if(DivAthlete is null,0,if(ClAthlete is null,0,DivAthlete and ClAthlete)) where EnTournament={$_SESSION['TourId']}"); // // deletes the qualifications entry for non athletes // safe_w_sql("delete from Qualifications where QuId in (select EnId from Entries where EnAthlete!='1' and EnTournament={$_SESSION['TourId']})"); MakeIndAbs(); $CFG->TRACE_QUERRIES = $OldTrace; } } $PAGE_TITLE = get_text('ListLoad', 'Tournament'); include 'Common/Templates/head.php';
} } } else { if ($Errore) { $q = safe_r_sql("select {$FIELD} WhichField from Entries where EnId={$ID}"); if ($r = safe_fetch($q)) { $value = $r->WhichField; } else { $value = ''; } } else { if ($ID) { // update safe_w_sql("update Entries set {$FIELD}=" . StrSafe_DB($value) . ($resetPrintBadge ? ", EnBadgePrinted='0000-00-00 00:00:00'" : "") . " where EnId={$ID}"); } else { // insert a new one and gives alert back to the page safe_w_sql("insert into Entries set EnTournament={$_SESSION['TourId']}, {$FIELD}=" . StrSafe_DB($value) . ""); $ID = safe_w_last_id(); safe_w_sql("insert into Qualifications set QuId={$ID}" . ($session ? ", QuSession={$session}" . ($targetno ? ", QuTargetno=" . StrSafe_DB($session . $targetno) : '') : '')); } } } } header('Content-Type: text/xml'); print '<response>' . "\n"; print '<error>' . intval($Errore) . '</error>' . "\n"; print '<update>' . $update . '</update>' . "\n"; print '<id>' . $ID . '</id>' . "\n"; print '<field>' . $field . '</field>' . "\n"; print '<value><![CDATA[' . stripslashes($value) . ']]></value>' . "\n"; print '</response>' . "\n";