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>";
  }
}
{
    // Gets the group received from the registration factory.
    $group = utf8_decode($_REQUEST['group']);
    $query = "SELECT capacity FROM groups WHERE name='{$group}'";
    $result = $conn->query($query);
    $result = mysqli_fetch_row($result);
    echo $result[0];
}
// Try to make the connection with the database.
$connection = new Connection();
$conn = $connection->createConnection();
if ($conn) {
    // Get the action from the registration factory.
    $action = $_REQUEST['action'];
    if ($action === 'insert') {
        insertPerson($conn);
    } else {
        if ($action === 'validateId') {
            validateId($conn);
        } else {
            if ($action === 'validateEmail') {
                validateEmail($conn);
            } else {
                if ($action === 'validateGroup') {
                    validateGroup($conn);
                } else {
                    if ($action === 'decrement') {
                        decrementCapacity($conn);
                    } else {
                        if ($action === 'capacity') {
                            isThereCapacity($conn);