function list2query($str, $pre) { $names = array(); $ids = array(); $list = quotesplit(",", $str); $list = array_map("sql_escape_string", $list); foreach ($list as $al) { if (preg_match("/^id:\\d+\$/", $al)) { $ids[] = substr($al, 3); } else { $a = getMatches("{$pre}_name", $al); if ($a) { $names[] = $a; } else { $names[] = "'{$al}'"; } } } $q = ""; if (count($names) > 0) { $q .= "{$pre}_name IN(" . join(", ", $names) . ")"; } if (count($names) > 0 && count($ids) > 0) { $q .= " OR "; } if (count($ids) > 0) { $q .= "{$pre}_id IN(" . join(", ", $ids) . ")"; } return strlen($q) > 0 ? $q : false; }
function calcPostEventRatings($event, $format) { global $db; $players = getEntryRatings($event, $format); $matches = getMatches($event); foreach ($matches as $match) { $aPts = 0.5; $bPts = 0.5; if (strcmp($match['result'], 'A') == 0) { $aPts = 1.0; $bPts = 0.0; $players[$match['playera']]['wins']++; $players[$match['playerb']]['losses']++; } elseif (strcmp($match['result'], 'B') == 0) { $aPts = 0.0; $bPts = 1.0; $players[$match['playerb']]['wins']++; $players[$match['playera']]['losses']++; } $newA = newRating($players[$match['playera']]['rating'], $players[$match['playerb']]['rating'], $aPts, $match['kvalue']); $newB = newRating($players[$match['playerb']]['rating'], $players[$match['playera']]['rating'], $bPts, $match['kvalue']); $players[$match['playera']]['rating'] = $newA; $players[$match['playerb']]['rating'] = $newB; } return $players; }
function calcPostEventRatings($event, $format) { $players = getEntryRatings($event, $format); $matches = getMatches($event); for ($ndx = 0; $ndx < sizeof($matches); $ndx++) { $aPts = 0.5; $bPts = 0.5; if (strcmp($matches[$ndx]['result'], 'A') == 0) { $aPts = 1.0; $bPts = 0.0; $players[$matches[$ndx]['playera']]['wins']++; $players[$matches[$ndx]['playerb']]['losses']++; } elseif (strcmp($matches[$ndx]['result'], 'B') == 0) { $aPts = 0.0; $bPts = 1.0; $players[$matches[$ndx]['playerb']]['wins']++; $players[$matches[$ndx]['playera']]['losses']++; } $newA = newRating($players[$matches[$ndx]['playera']]['rating'], $players[$matches[$ndx]['playerb']]['rating'], $aPts, $matches[$ndx]['kvalue']); $newB = newRating($players[$matches[$ndx]['playerb']]['rating'], $players[$matches[$ndx]['playera']]['rating'], $bPts, $matches[$ndx]['kvalue']); # if(strcmp($format, "Other Formats") == 0) { # if(strcasecmp($matches[$ndx]['playera'], 'kingritz') == 0) { # printf("%s\n", $event); # printf("%d -> %d\n", $players[$matches[$ndx]['playera']]['rating'], $newA);} # if(strcasecmp($matches[$ndx]['playerb'], 'kingritz') == 0) { # printf("%s\n", $event); # printf("%d -> %d\n", $players[$matches[$ndx]['playerb']]['rating'], $newB);} # } $players[$matches[$ndx]['playera']]['rating'] = $newA; $players[$matches[$ndx]['playerb']]['rating'] = $newB; } return $players; }
function transformFile($file) { $output_contents = array(); //read the file line-wise, do transformations,if needed, $file_handle = fopen($file, 'r'); // and write result into array $output_contents while ($line = fgets($file_handle)) { if ($aux = getMatches(REGEX_GLOBAL_DEC, $line, 'i')) { //if something like // {some prefix goes here}global $var_1,$var_2,...,var_n;{some suffix} $fix = explode($aux[0], $line); // is found, replace it by // {some prefix goes here}global $DIC;{some suffix} // {some prefix goes here}$var_1 = $DIC['var_1']; // {some prefix goes here}... $prefix = $fix[0]; $suffix = $fix[1]; $output_contents[] = $prefix . 'global $DIC;' . $suffix; foreach ($vars = getMatches(REGEX_VAR, $aux[0]) as $var) { $output_contents[] = $prefix . $var . ' = $DIC[\'' . getMatches(REGEX_VARNAME, $var)[0] . '\'];' . PHP_EOL; } } else { if (preg_match('/' . REGEX_GLOBAL_ARRAY . '/', $line)) { //if something like {stuff}$GLOBALS["var"]{more_stuff} $output_contents[] = preg_replace_callback('/' . REGEX_GLOBAL_ARRAY . '/', function ($match) { return $match[1] . '[\'DIC\']' . $match[2]; }, $line); } else { $output_contents[] = $line; //if we find isolated keywords global or $GLOBALS, something may be fishy, // better write a warning that is easily spotted // but does not change code functionality if (1 === preg_match('/\\sglobal\\s/i', $line) && 0 === preg_match('/\\sglobal\\s\\$DIC/i', $line)) { $output_contents[] = '// !!!DIC refactoring-script warning.!!!' . PHP_EOL . '// There is an isolated \'global\' whithout any variable behind.' . PHP_EOL . '// Either this is a comment, or something is seriously wrong' . PHP_EOL; } if (1 === preg_match('/\\$GLOBALS/', $line) && 0 === preg_match('/\\$GLOBALS\\s*\\[\'DIC\'\\]/', $line)) { $output_contents[] = '// !!!DIC refactoring-script warning.!!!' . PHP_EOL . '// There is an isolated \'$GLOBALS\' whithout any key behind.' . PHP_EOL . '// Either this is a comment, or something is seriously wrong' . PHP_EOL; } } } } fclose($file_handle); return $output_contents; }
exit("Invalid Username and Password Combination."); } if (alreadyPicked($userId, $week, $db)) { exit("You already picked this week."); } $picks = array(); $opponentPicks = array(); while (list($key, $value) = each($_POST)) { $teamId = determineTeamId(htmlspecialchars($value), $db); if ($week > 1 && didPick($teamId, $userId, $week - 1, $db)) { exit("You picked {$value} last week, choose again."); } array_push($picks, $teamId); } define("NUM_TO_PICK", 7); if (count($picks) != NUM_TO_PICK) { exit("You must make a selection for all conferences."); } $matches = getMatches($week, $db); $opponentId = determineOpponent($userId, $matches); fillPicks($opponentPicks, $week, $opponentId, $db); $samePicks = doPicksMatch($picks, $opponentPicks); if ($samePicks) { exit("Your opponent picked all of the same teams, please change at least one team."); } foreach ($picks as $teamId) { if (!isset($teamId) || !$db->insertPick($userId, $week, $teamId)) { exit('Error submitting form.'); } } exit("success");
function init() { if (empty($_POST['letters']) || empty($_POST['wordlen'])) { $html = getHTML(1); } else { $letters = trim($_POST['letters']); //Remove spaces in between $letters = strtolower(str_replace(' ', '', $letters)); $wordlen = intval($_POST['wordlen']); if ($wordlen <= strlen($letters)) { $success = getMatches($letters, $wordlen); $html = getHTML(0, $success); } else { $success = array(); $html = getHTML(0, $success); } } echo $html; }
function getAllMatches($maxWeek, $db) { $allMatches = array(); for ($i = 1; $i <= $maxWeek; ++$i) { $allMatches[$i] = getMatches($i, $db); } return $allMatches; }