function print_disambiguation_options(&$entry)
{
    global $session_data;
    global $import_id;
    global $heurist_rectypes;
    if (!$heurist_rectypes) {
        load_heurist_rectypes();
    }
    if (count($session_data['ambiguities']) == 0) {
        // This is the first ambiguous record, print out a header
        ?>
        <br>
        <hr>
        <h1>Potential duplicates</h1>
        <div style="margin-left: 3ex;">
            <p><b>The following record(s) are potential duplicates.  Please choose the appropriate action by selecting the radio buttons below.</b></p>
            <p><a href="NEW record" onClick="return false;"><b>NEW</b></a> indicates the record being imported.  Selecting this will create a new record in Heurist.</p>
            <p>Numbers indicate an existing record ID in Heurist.<br>
                <span style="color: mediumvioletred;">Purple text flags any differences between the imported record and existing records.</span></p>
        </div>
        <?php 
    }
    // generate a random number associated with this entry (it doesn't have an ID yet, remember?)
    $nonce = rand();
    $session_data['ambiguities'][$nonce] =& $entry;
    if ($entry->getPotentialMatches()) {
        $ambig_entry =& $entry;
    } else {
        $ambig_entry =& $entry->_ancestor;
    }
    //disambiguation searches the containment heirarchy for near matches and if found points to it _ancestor to it
    $entry_type = $heurist_rectypes[$entry->getReferenceType()]['rty_Name'];
    $compare_link = "interface/showSideBySidee.php?ids=" . $ambig_entry->getBiblioID() . "," . join(',', $ambig_entry->getPotentialMatches());
    ?>
    <hr>
    <div class="ambiguous">
        <?php 
    if ($entry == $ambig_entry) {
        ?>
            <div><span style="font-weight: bold;"><?php 
        echo $entry_type;
        ?>
</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=<?php 
        echo $compare_link;
        ?>
 onClick="var win = open(href, 'compare', 'width=600,height=300,scrollbars=1,resizable=1'); win.focus(); return false;">compare versions</a></div>
            <?php 
    } else {
        ?>
            <div><span style="font-weight: bold;"><?php 
        echo $heurist_rectypes[$ambig_entry->getReferenceType()]["rty_Name"];
        ?>
</span> of &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=<?php 
        echo $compare_link;
        ?>
 onClick="var win = open(href, 'compare', 'width=600,height=300,scrollbars=1,resizable=1'); win.focus(); return false;">compare versions</a></div>
            <div style="margin-top: 1ex; margin-left: 3ex; background-color: #f0f0f0;"><?php 
        echo htmlspecialchars($entry->getTitle());
        ?>
 <i>(<?php 
        echo $entry_type;
        ?>
)</i></div>
            <?php 
    }
    ?>

        <table class="new_bib" style="margin: 1em; margin-bottom: 1ex;">
            <tr>
                <td style="text-align: right;"><b>NEW</b>&nbsp;</td>
                <td><input type="radio" name="ambig[<?php 
    echo $nonce;
    ?>
]" value="-1" class="radio" id=<?php 
    echo $nonce;
    ?>
></td>
                <td><label for=<?php 
    echo $nonce;
    ?>
><b><?php 
    echo htmlspecialchars($ambig_entry->getTitle());
    ?>
</b></label></td>
            </tr>
            <?php 
    $res = mysql_query('select rec_ID,rec_Title,
                new_levenshtein(rec_Hash,upper("' . mysql_real_escape_string($ambig_entry->getHHash()) . '")) as diff1,
                new_levenshtein(upper(rec_Title),upper("' . mysql_real_escape_string($ambig_entry->getTitle()) . '")) as diff2
                from Records where rec_ID in (' . join(',', $ambig_entry->getPotentialMatches()) . ') order by diff1, diff2');
    $is_first = true;
    while ($bib = mysql_fetch_assoc($res)) {
        $title_with_deltas = levenshtein_delta(strip_tags($bib['rec_Title']), strip_tags($ambig_entry->getTitle()));
        ?>
                <tr>
                    <td style="text-align: right;white-space:nowrap;"><?php 
        echo $bib['rec_ID'];
        ?>
&nbsp;</td>
                    <td><input type="radio" name="ambig[<?php 
        echo $nonce;
        ?>
]" value="<?php 
        echo $bib['rec_ID'];
        ?>
" class="radio" <?php 
        echo $is_first ? "checked" : "";
        ?>
 id=<?php 
        echo $bib['rec_ID'] . '-' . $nonce;
        ?>
>
                    <td><label for=<?php 
        echo $bib['rec_ID'] . '-' . $nonce;
        ?>
><b title="<?php 
        echo htmlspecialchars($bib['rec_Title']);
        ?>
"><?php 
        echo $title_with_deltas;
        ?>
</b></label></td>
                </tr>

                <?php 
        $is_first = false;
    }
    ?>
        </table>
    </div>
    <?php 
}
 function getTitle()
 {
     // Construct/retrieve the formatted title for this entry,
     // based on the reference type's title mask.
     global $heurist_rectypes;
     if (!$heurist_rectypes) {
         load_heurist_rectypes();
     }
     if (!$this->getBiblioID()) {
         return "";
     }
     if ($this->_title) {
         return $this->_title;
     }
     $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask'];
     $this->_title = fill_title_mask($mask, $this->getBiblioID(), $this->getReferenceType());
     return $this->_title;
     // fin     FIXME  the code below never executes, looks old and refactored into TitleMask.php ?remove?
     global $heurist_rectypes, $bib_type_names;
     if (!$heurist_rectypes) {
         load_heurist_rectypes();
     }
     if (!$bib_type_names) {
         load_bib_type_names();
     }
     $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask'];
     if (!$mask) {
         return '';
     }
     if (!preg_match_all('/\\[\\[|\\]\\]|(\\s*(\\[\\s*([^]]+)\\s*\\]))/s', $mask, $matches)) {
         return $this->_title = $mask;
     }
     // nothing to do -- no substitutions
     $replacements = array();
     for ($i = 0; $i < count($matches[1]); ++$i) {
         /*
          * $matches[3][$i] contains the field name as supplied (the string that we look up),
          * $matches[2][$i] contains the field plus surrounding whitespace and containing brackets
          *        (this is what we replace if there is a substitution)
          * $matches[1][$i] contains the field plus surrounding whitespace and containing brackets and LEADING WHITESPACE
          *        (this is what we replace with an empty string if there is no substitution value available)
          */
         $value = $this->get_field_value($matches[3][$i]);
         if ($value) {
             $replacements[$matches[2][$i]] = $value;
         } else {
             $replacements[$matches[1][$i]] = '';
         }
     }
     $replacements['magic-open-bracket'] = '[';
     $replacements['magic-close-bracket'] = ']';
     $title = array_str_replace(array_keys($replacements), array_values($replacements), $mask);
     $title = preg_replace('!^[-:;,./\\s]*(.*?)[-:;,/\\s]*$!s', '\\1', $title);
     $title = preg_replace('!\\([-:;,./\\s]+\\)!s', '', $title);
     $title = preg_replace('!\\([-:;,./\\s]*(.*?)[-:;,./\\s]*\\)!s', '(\\1)', $title);
     $title = preg_replace('!\\([-:;,./\\s]*\\)|\\[[-:;,./\\s]*\\]!s', '', $title);
     $title = preg_replace('!,,+!s', ',', $title);
     $title = preg_replace('!\\s+,!s', ',', $title);
     $title = preg_replace('!  +!s', ' ', $title);
     /* Clean up miscellaneous stray punctuation &c. */
     return $this->_title = trim($title);
 }