function finishUnfinishedPersons () {
#----------------------------------------------------------------------

  #--- Process all cases.
  while( true ){

    #--- Get old name and country from the case.
    $caseNr++;
    $oldNameAndCountry = getRawParamThisShouldBeAnException( "oldNameAndCountry$caseNr" );
    
    #--- If empty, we've reach the end of the list and can stop.
    if( ! $oldNameAndCountry )
      break;

    #--- Separate old name and country, and get the action.
    list( $oldName, $oldCountry ) = explode( '|', $oldNameAndCountry );    
    $action = getRawParamThisShouldBeAnException( "action$caseNr" );

    #--- If no action or 'skip' chosen, skip it.
    if( ! $action  ||  $action == 'skip' )
      continue;
    
    #--- If 'new' chosen, treat the person as new.
    if( $action == 'new' ){
      
      #--- First get the new name, country, and semi-id.
      $newName    = getRawParamThisShouldBeAnException( "name$caseNr" );
      $newCountry = getRawParamThisShouldBeAnException( "country$caseNr" );
      $newSemiId  = getRawParamThisShouldBeAnException( "semiId$caseNr" );

      #--- Complete the id.
      $newId = completeId( $newSemiId );
      
      #--- Insert the new person into the Persons table.
      insertPerson( $oldName, $oldCountry, $newName, $newCountry, $newId );

      #--- Adapt the Results table entries.
      adaptResults( $oldName, $oldCountry, $newName, $newCountry, $newId );
    }
    #--- Otherwise adopt another personality.
    else {
    
      #--- Scream if error.      
      if( count( explode( '|', $action )) != 3 ){
        showErrorMessage( "invalid action '$action'" );
        continue;
      }
      
      #--- Get the data from the other person.
      list( $newName, $newCountry, $newId ) = explode( '|', $action );

      #--- Adapt the Results table entries.
      adaptResults( $oldName, $oldCountry, $newName, $newCountry, $newId );      
    }
    
    #--- Separator after each person.
    echo "<hr>";
  }
}
Ejemplo n.º 2
0
function showMatchingPersons()
{
    #----------------------------------------------------------------------
    global $chosenPatternHtml, $chosenPatternMysql, $chosenEventId, $chosenRegionId;
    #--- If nothing chosen yet, display a help message.
    if (!$chosenPatternHtml && !$chosenEventId && !$chosenRegionId) {
        echo "<div style='width:85%; margin:auto; font-size:1.00em; font-weight:bold'><p>For the name field search, enter any name or name parts and don't worry about letter variations. For example, 'or joe' (enter without the quotes) will among others also find Jo&euml;l van Noort.</p></div>";
        return;
    }
    #--- The pattern should contain at least 2 non-whitespace characters.
    if (!preg_match('/\\S.*\\S/', $chosenPatternHtml)) {
        noticeBox3(-1, "Please Enter at least 2 characters.");
        echo "<div style='width:85%; margin:auto; font-size:1.00em; font-weight:bold'><p>For the name field search, enter any name or name parts and don't worry about letter variations. For example, 'or joe' (enter without the quotes) will among others also find Jo&euml;l van Noort.</p></div>";
        return;
    }
    #--- Otherwise, build up a query to search for people.
    global $wcadb_conn;
    $params = array(0 => '');
    $parts = array();
    $rawPattern = getRawParamThisShouldBeAnException('pattern');
    #--- Build the nameCondition (all searched parts must occur).
    $nameCondition = "";
    foreach (explode(' ', $rawPattern) as $namePart) {
        $parts[$namePart] = '%' . $namePart . '%';
        $params[0] .= 's';
        $params[] =& $parts[$namePart];
        $likeId = '';
        if (ctype_alnum($namePart)) {
            $params[0] .= 's';
            $params[] =& $parts[$namePart];
            $likeId = ' OR person.id LIKE ?';
        }
        $nameCondition .= ' AND (person.name LIKE ?' . $likeId . ')';
    }
    #--- Build the eventCondition (if any).
    if ($chosenEventId) {
        $eventConditionPart1 = ', (SELECT DISTINCT personId FROM ConciseSingleResults WHERE 1 ' . eventCondition() . ') result';
        $eventConditionPart2 = 'AND person.id = result.personId';
    } else {
        $eventConditionPart1 = '';
        $eventConditionPart2 = '';
    }
    #--- Do the query!
    $query = 'SELECT DISTINCT person.id AS personId, person.name AS personName, country.name AS countryName
            FROM Persons AS person, Countries AS country' . $eventConditionPart1 . ' WHERE ' . randomDebug() . $nameCondition . regionCondition('') . ' AND country.id = person.countryId' . $eventConditionPart2 . ' ORDER BY personName, countryName, personId';
    $persons = $wcadb_conn->boundQuery($query, $params);
    $count = count($persons);
    $ext = $count != 1 ? 's' : '';
    tableBegin('results', 3);
    tableCaption(false, spaced(array("{$count} person{$ext} matching:", eventName($chosenEventId), chosenRegionName($chosenRegionId), $chosenPatternHtml ? "\"{$chosenPatternHtml}\"" : '')));
    tableHeader(explode('|', 'Person|WCA id|Citizen of'), array(2 => 'class="f"'));
    foreach ($persons as $person) {
        extract($person);
        tableRow(array(personLink($personId, $personName), $personId, $countryName));
    }
    tableEnd();
}
function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenId, $chosenConfirm, $chosenName, $chosenNameHtml, $chosenCountryId, $chosenGender, $chosenDay, $chosenMonth, $chosenYear, $chosenUpdate, $chosenFix;
    $chosenConfirm = getBooleanParam('confirm');
    $chosenUpdate = getBooleanParam('update');
    $chosenFix = getBooleanParam('fix');
    $chosenId = getNormalParam('id');
    // Gah, this is awful. We can't call getNormalParam because it refuses to
    // return anything if the parameter has a quote in it. We don't want to call
    // getMysqlParam, as we're using pdo_query throughout this file, and we don't
    // want double escaping to occur.
    $chosenName = getRawParamThisShouldBeAnException('name');
    $chosenNameHtml = getHtmlParam('name');
    $chosenCountryId = getNormalParam('countryId');
    $chosenGender = getNormalParam('gender');
    $chosenDay = getNormalParam('day');
    $chosenMonth = getNormalParam('month');
    $chosenYear = getNormalParam('year');
}
function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenCompetitionId, $chosenType, $chosenText, $chosenUri;
    global $chosenSubmitterName, $chosenSubmitterEmail, $chosenSubmitterComment;
    global $chosenTextHtml, $chosenUriHtml, $chosenSubmitterNameHtml, $chosenSubmitterEmailHtml, $chosenSubmitterCommentHtml;
    global $chosenRecaptchaChallenge, $chosenRecaptchaResponse;
    $chosenCompetitionId = getNormalParam('competitionId');
    $chosenType = getNormalParam('type');
    $chosenText = getMysqlParam('text');
    $chosenUri = getMysqlParam('uri');
    $chosenSubmitterName = getMysqlParam('submitterName');
    $chosenSubmitterEmail = getMysqlParam('submitterEmail');
    $chosenSubmitterComment = getMysqlParam('submitterComment');
    $chosenTextHtml = getHtmlParam('text');
    $chosenUriHtml = getHtmlParam('uri');
    $chosenSubmitterNameHtml = getHtmlParam('submitterName');
    $chosenSubmitterEmailHtml = getHtmlParam('submitterEmail');
    $chosenSubmitterCommentHtml = getHtmlParam('submitterComment');
    $chosenRecaptchaChallenge = getRawParamThisShouldBeAnException('recaptcha_challenge_field');
    $chosenRecaptchaResponse = getRawParamThisShouldBeAnException('recaptcha_response_field');
}
        $command = 'UPDATE Persons SET name = ? WHERE name = ?';
        $params = array('ss', &$new_name, &$old_name);
        break;
    case "fix_results_name":
        $old_name = getRawParamThisShouldBeAnException('old_name');
        $new_name = getRawParamThisShouldBeAnException('new_name');
        $command = 'UPDATE Results SET personName = ? WHERE personName = ?';
        $params = array('ss', &$new_name, &$old_name);
        break;
    case "fix_results_data":
        $old_id = getRawParamThisShouldBeAnException('old_id');
        $old_name = getRawParamThisShouldBeAnException('old_name');
        $old_country = getRawParamThisShouldBeAnException('old_country');
        $new_id = getRawParamThisShouldBeAnException('new_id');
        $new_name = getRawParamThisShouldBeAnException('new_name');
        $new_country = getRawParamThisShouldBeAnException('new_country');
        $command = 'UPDATE Results SET personId = ?, personName = ?, countryId = ? WHERE personId = ? AND personName = ? AND countryId = ?';
        $params = array('ssssss', &$new_id, &$new_name, &$new_country, &$old_id, &$old_name, &$old_country);
        break;
}
if ($action && $command && !empty($params)) {
    $wcadb_conn->boundCommand($command, $params);
    print '<p>The following query was executed:<br /><br />';
    print highlight($command);
    print '<br />With parameters:';
    foreach ($params as $param) {
        print '<br /> * <span style="color:#F00">' . $param . '</span>';
    }
    print '</p>';
} else {
    print '<p>Nothing to do.</p>';
function wcaDebug()
{
    #----------------------------------------------------------------------
    // We can't turn on wcaDebug when run via the cli, because it neuters
    // webroot/results/misc/evolution/update7205.php and
    // webroot/results/misc/missing_averages/update7205.php.
    //return php_sapi_name() == "cli" || getRawParamThisShouldBeAnException( 'debug5926' );
    return getRawParamThisShouldBeAnException('debug5926');
}