function toIS4C($mode, $member, $updated)
{
    global $is4cOps;
    global $debug;
    global $dryRun;
    global $is4cTableNames;
    global $dieMail;
    if ($debug) {
        $ans = readline("In toIS4C mode: {$mode} {$member} > ");
    }
    // debug=2 allows inserts and updates while displaying messages.
    //$debug = 2;
    if ($dryRun) {
        echo "Bailing on dryRun.";
        return True;
    }
    // Get all the data from Civi for this member.
    // You don't know contact_id at this point.
    $row = selectCivi($member);
    if ($mode == "insert") {
        foreach ($is4cTableNames as $table) {
            $is4cOps["{$table}"] = "insert";
        }
    } else {
        // Note which IS4C operations will be inserts, which updates.
        // Find out whether the operation to each table will be insert or update.
        $is4cOps = searchIS4C2($member);
        if (preg_match("/^Error/", $is4cOps[0][0])) {
            dieHere("{$is4cOps[0][0]}", $dieMail);
        }
    }
    // Populate the local arrays
    // and create the DML statements.
    assignLocalI($row, $is4cOps, $updated);
    if ($debug) {
        goOrDie("Before DML for member: {$member} debug: {$debug}");
        1;
    }
    // Make the changes to IS4C tables.
    $resultString = insertToIS4C($mode);
    if ($resultString != "OK") {
        dieHere("{$resultString}", $dieMail);
    }
    // Important to update after insert so custdata.LastChange is last thing assigned.
    // Important to update custdata if any related table is inserted or updated.
    $resultString = updateIS4C($mode);
    if ($resultString != "OK") {
        dieHere("{$resultString}", $dieMail);
    }
    if ($debug) {
        goOrDie("After DML for member: {$member} ");
    }
    // Clear for next operation.
    //  Better to do at start.
    // Each IS4C table is represented by an assoc array.
    clearIs4cWorkVars();
    $is4cOps = array();
    // Is the clearing needed?
    return True;
    // toIS4C()
}
if ($writeIS4C) {
    //echo "To DML is4cOp >${is4cOp}< CardNo >$custdata[CardNo]<\n";
    // Is the op for the just-finished member to be insert or update?
    if (True || $is4cOp1 == "insert") {
        // Insert the records for this Individual, Household or Organization.
        $resultString = insertToIS4C();
        if ($resultString != "OK") {
            //$dbConn->close();
            //$dbConn2->close();
            dieHere("{$resultString}");
        }
        //$insertCount++;
    }
    // update existing members.
    if (True || $is4cOp1 == "update") {
        $resultString = updateIS4C();
        if ($resultString != "OK") {
            //$dbConn->close();
            //$dbConn2->close();
            dieHere("{$resultString}");
        }
        //$updateCount++;
    }
    /*
    else {
        //$dbConn->close();
        //$dbConn2->close();
        dieHere("Unknown is4cOp1 >${is4cOp1}< CardNo >$custdata[CardNo]<\n");
    }
    */
    // The last Civi row.