function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("SELECT id, name, t, url, party " . "FROM catavencu_2008 " . "WHERE idperson=0");
    while ($r = mysql_fetch_array($s)) {
        $name = trim($r['name']);
        $idString = '' . $r['url'] . ', ' . $r['party'];
        $persons = getPersonsByName($name, $idString, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "catavencu/2008", $r['url']);
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE catavencu_2008 " . "SET idperson={$person->id} " . "WHERE id=" . $r['id']);
        }
    }
    printJsCommitCookieScript();
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("\n    SELECT c.id, c.name, c.idm\n    FROM cdep_2008_deputies AS c\n    where idperson=0");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['name'];
        // Get the party
        $ps = mysql_query("\n        SELECT c.iddep, p.id, p.name\n        FROM cdep_2008_belong as c\n        LEFT JOIN parties AS p ON p.id = c.idparty\n        WHERE iddep = {$r['idm']}\n        ORDER BY c.time DESC");
        $rs = mysql_fetch_array($ps);
        $idString = $rs['name'];
        $persons = getPersonsByName($name, $idString, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "cdep/2008", "http://www.cdep.ro/pls/parlam/structura.mp?idm={$r['idm']}&cam=2&leg=2008", 1230768000);
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE cdep_2008_deputies " . "SET idperson={$person->id} " . "WHERE id=" . $r['id']);
        }
    }
    printJsCommitCookieScript();
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("\n    SELECT q.id, q.name, count(*) as num\n    FROM news_qualifiers AS q\n    WHERE idperson=0\n    GROUP BY name\n    ORDER BY num DESC");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['name'];
        // Get the party
        $idString = 'none now';
        $persons = getPersonsByName($name, $idString, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
            mysql_query("UPDATE news_qualifiers " . "SET idperson={$person->id} " . "WHERE name='" . $r['name'] . "'");
        }
        info('<a href="/politica/api/add_person_update_qualifier.php?name=' . $r['name'] . '" target="_blank">add</a>');
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE news_qualifiers " . "SET idperson={$person->id} " . "WHERE name='" . $r['name'] . "'");
        }
    }
    printJsCommitCookieScript();
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("\n    SELECT c.id, c.name\n    FROM govro_people AS c\n    where idperson=0");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['name'];
        // Get the party
        $idString = 'none now';
        $persons = getPersonsByName($name, $idString, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "gov/ro", "www.gov.ro", 1258848000);
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE govro_people " . "SET idperson={$person->id} " . "WHERE id=" . $r['id']);
        }
    }
    printJsCommitCookieScript();
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("SELECT e.id, e.name, e.idparty, p.name as pname \n    FROM euro_2009_candidates AS e\n    LEFT JOIN parties AS p ON p.id = e.idparty \n    where idperson=0\n    ");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['name'];
        $idString = '' . $r['pname'] . '';
        $persons = getPersonsByName($name, $idString, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "euro/2009", "http://ro.wikipedia.org/wiki/Alegeri_pentru_Parlamentul_European_%C3%AEn_Rom%C3%A2nia,_2009", 1244349442);
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE euro_2009_candidates " . "SET idperson={$person->id} " . "WHERE id=" . $r['id']);
        }
    }
    printJsCommitCookieScript();
}
/**
 * Returns a list of persons from the people database that could potentially
 * be the persons for this name.
 *
 * @param {string} name The name of the person we are looking for.
 * @param {string} opt_idString A string that should identify the name we are
 *     searching for in the logs, when we print it. A good example is when
 *     adding names from the 2008 elections, the id string could represent the
 *     college he is running for (which narrows down the identification).
 * @param {Function} A function to call in order to get extra information
 *     about a person found as a match and display it in the extra info field.
 *
 * @return {Array.<Person>}
 */
function getPersonsByName($name, $opt_idstring = '', $opt_infoFunc = emptyInfoFunction)
{
    global $people;
    global $ambiguities;
    global $queries;
    global $MAX_QUERIES_BEFORE_COMMIT;
    if ($queries >= $MAX_QUERIES_BEFORE_COMMIT) {
        printJsCommitCookieScript();
    }
    $queries++;
    // If I have an ambiguity solver, skip everything else, we know exactly
    // what we want.
    if ($ambiguities[$name]) {
        return array(getNonAmbiguousPerson($name));
    }
    $parts = array();
    $cleanName = implode(' ', Person::addNameToAllNames($parts, $name));
    $matches = array();
    if (count($people)) {
        foreach ($people as $key => $person) {
            if ($key == $cleanName || $person->isSubsetOf($parts) || $person->isSupersetFor($parts)) {
                $matches[] = $person;
            }
        }
    }
    // If we find more than one person, fail immediately and ask the developer
    // to resolve the ambiguity.
    if (count($matches) > 1) {
        if ($ambiguities[$name]) {
            return array(getNonAmbiguousPerson($name));
        }
        info('[' . $name . '] ' . $opt_idstring . ' - se potivește cu:');
        foreach ($matches as $m) {
            printMatchDecision($name, $m);
        }
        printResolveAmbiguityToHimself($name);
        die('This ambiguity needs to be resolved before we proceed.');
    } else {
        if (count($matches) == 1) {
            $m = $matches[0];
            // If this name is a subset or superset - if the match is not exact
            if ($m->name != $cleanName) {
                info("------ Found one non exact match --------");
                info(sprintf("[%35s] %s - se potrivește cu", $name, $opt_idstring));
                printMatchDecision($name, $matches[0]);
                printResolveAmbiguityToHimself($name);
                if (function_exists("shouldAddDetailsFunction")) {
                    shouldAddDetailsFunction($name);
                }
                die('This ambiguity needs to be resolved before we proceed.');
            }
        }
    }
    if (count($matches) == 1) {
        info(sprintf("Found  {%40s} %20s / %20s", $name, $opt_idstring, $opt_infoFunc($matches[0], $opt_idstring)));
    }
    return $matches;
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("SELECT e.id, e.name, e.text \n    FROM euro_parliament_2007_qvorum AS e\n    WHERE idperson=0\n    ");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['name'];
        $persons = getPersonsByName($name, $name, infoFunction);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $r['name']);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "qvorum/2009", "http://qvorum.ro/ViewAnalyse.aspx?analyseID=13", 1242508980);
        if (strpos($r['text'], "o contribuţie slabă") > 0) {
            $score = 0;
        } else {
            if (strpos($r['text'], "o contribuţie medie") > 0) {
                $score = 1;
            } else {
                if (strpos($r['text'], "o contribuţie bună") > 0) {
                    $score = 2;
                } else {
                    if (strpos($r['text'], "o contribuţie deosebită") > 0) {
                        $score = 3;
                    }
                }
            }
        }
        mysql_query("UPDATE euro_parliament_2007_qvorum SET score={$score} \n                 WHERE id={$r['id']}");
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB) {
            mysql_query("UPDATE euro_parliament_2007_qvorum " . "SET idperson={$person->id} " . "WHERE id=" . $r['id']);
        }
    }
    printJsCommitCookieScript();
}
function candidatesArePeopleToo()
{
    global $FLAG_CAN_CHANGE_DB;
    $s = mysql_query("SELECT * FROM results_2008_candidates WHERE idperson=0");
    while ($r = mysql_fetch_array($s)) {
        $name = $r['nume'];
        $sid = $r['id'];
        list($cod, $judet) = split(" ", $r['college']);
        $idString = "{$judet}-{$cod}";
        if ($judet == 'Strainatate') {
            $url = "http://www.thinkopolis.eu/colegiu/Diaspora-{$cod}";
        } else {
            $jsel = mysql_query("SELECT id FROM counties WHERE name='{$judet}'");
            if ($rsel = mysql_fetch_array($jsel)) {
                $url = "http://alegeri-2008.ro/candidati/x-{$rsel['id']}/";
            }
        }
        // Let's attempt to create an id string. Best guess we have for these
        // people is the info-alegeri site. We would like to avoid linking to the
        // BEC pdf's, even though those would be the best ones.
        $persons = getPersonsByName($name, $idString, getExistingPersonInfo);
        // If I reached this point, I know for sure I either have one
        // or zero matches, there are no ambiguities.
        if (count($persons) == 0) {
            $person = addPersonToDatabase($name, $name);
        } else {
            $person = $persons[0];
        }
        // First and foremost, attempt to add this to the person's history.
        addPersonHistory($person->id, "results/2008", $url);
        // Locate these people and update them in several tables now.
        // We're mainly interested in updating the ID to the new ID that
        // will be in the People database, from the previous ID that was
        // the senator's ID in the senators table.
        if ($FLAG_CAN_CHANGE_DB == true) {
            mysql_query("UPDATE results_2008_candidates " . "SET idperson={$person->id} " . "WHERE id={$sid}");
        }
    }
    printJsCommitCookieScript();
}