function _get_word_list($projectid)
{
    $messages = array();
    // get the latest project text of all pages up to last possible round
    $last_possible_round = get_Round_for_round_number(MAX_NUM_PAGE_EDITING_ROUNDS);
    $pages_res = page_info_query($projectid, $last_possible_round->id, 'LE');
    $all_words_w_freq = get_distinct_words_in_text(get_page_texts($pages_res));
    // load site word lists for project languages
    $site_possible_bad_words = load_site_possible_bad_words_given_project($projectid);
    // now, remove any words that are already on the project's bad word list
    $site_possible_bad_words = array_diff($site_possible_bad_words, load_project_bad_words($projectid));
    // $site_possible_bad_words doesn't have frequency info,
    // so start with the info in $all_words_w_freq,
    // and extract the items where the key matches a key in $bad_words.
    $bad_words_w_freq = array_intersect_key($all_words_w_freq, array_flip($site_possible_bad_words));
    // multisort screws up all-numeric words so we need to preprocess first
    prep_numeric_keys_for_multisort($bad_words_w_freq);
    // sort the list by frequency, then by word
    array_multisort(array_values($bad_words_w_freq), SORT_DESC, array_map('strtolower', array_keys($bad_words_w_freq)), SORT_ASC, $bad_words_w_freq);
    return array($bad_words_w_freq, $messages);
}
 function show_visible_controls()
 {
     $goodWordData = html_safe($this->good_words);
     $badWordData = html_safe($this->bad_words);
     $fields = array("projectid" => _("Project ID"), "nameofwork" => _("Name of Work"), "authorsname" => _("Author's Name"), "projectmanager" => _("Project Manager"), "checkedoutby" => _("Post-Processor"), "language" => _("Language"));
     foreach ($fields as $field => $label) {
         echo "<tr>";
         echo "<td class='label'>{$label}</td>";
         echo "<td>" . $this->{$field} . "</td>";
         echo "</tr>";
     }
     $exist_OCR_pages = $this->number_of_pages_in_round(null) > 0;
     $exist_pages_in_P1_or_later = $this->number_of_pages_in_round(get_Round_for_round_number(1)) > 0;
     // due to some special circumstances, not all projects may have pages in P1
     // so we'll check to see if the project is in a state after P1 and count
     // that as just as good
     if (!$exist_pages_in_P1_or_later) {
         $current_project_round = get_Round_for_project_state($this->state);
         if ($current_project_round && $current_project_round->round_number > 1) {
             $exist_pages_in_P1_or_later = true;
         }
     }
     // if the project doesn't have any OCR pages and the project
     // has no P1 or later pages, report a message. The second criteria
     // is important for type-in projects that may have no OCR pages but
     // will have P1 or later pages
     if (!$exist_OCR_pages && !$exist_pages_in_P1_or_later) {
         echo "<tr>";
         echo "<td colspan='2'>";
         echo "<p class='error' style='text-align: center;'>";
         echo _("There are no pages associated with this project.");
         echo "</p>";
         echo "</td>";
         echo "</tr>";
     } else {
         echo "<tr>";
         echo "<td class='label' style='text-align: center;' colspan='2'>";
         echo _("WordCheck Tools and Reports");
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<td class='label'>" . _("Ad Hoc Word Details") . "</td>";
         echo "<td>" . new_window_link("show_adhoc_word_details.php?projectid={$this->projectid}", _("Show details for ad hoc words")) . "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<td class='label'>" . _("WordCheck Statistics") . "</td>";
         echo "<td>" . new_window_link("show_project_wordcheck_stats.php?projectid={$this->projectid}", _("Show WordCheck flagged word statistics")) . "</td>";
         echo "</tr>";
         if ($exist_pages_in_P1_or_later) {
             echo "<tr>";
             echo "<td class='label'>" . _("WordCheck Usage") . "</td>";
             echo "<td>" . new_window_link("show_project_wordcheck_usage.php?projectid={$this->projectid}", _("Show WordCheck interface usage")) . "</td>";
             echo "</tr>";
         }
         echo "<tr>";
         echo "<td class='label' style='text-align: center;' colspan='2'>";
         echo _("Word List Suggestion Tools");
         echo "</td>";
         echo "</tr>";
         echo "<tr>";
         echo "<td colspan='2'>";
         echo "<table width='100%'>";
         echo "<tr>";
         echo "<td style='width: 50%; text-align: center;' valign='top'>";
         echo "<p>";
         echo "<b>" . _("Words that WordCheck would currently flag:") . "</b><br>";
         echo new_window_link("show_current_flagged_words.php?projectid={$this->projectid}", _("Display"));
         echo " | ";
         echo "<a href='show_current_flagged_words.php?projectid={$this->projectid}&amp;format=file'>" . _("Download") . "</a>";
         echo "</p>";
         $suggestions = load_project_good_word_suggestions($this->projectid);
         if (count($suggestions)) {
             echo "<p>";
             echo "<b>" . _("Suggestions from proofreaders:") . "</b><br>";
             echo new_window_link("show_good_word_suggestions.php?projectid={$this->projectid}", _("Display"));
             echo " | ";
             echo "<a href='show_good_word_suggestions.php?projectid={$this->projectid}&amp;timeCutoff=0&amp;format=file'>" . _("Download") . "</a>";
             echo "</p>";
         }
         echo "</td>";
         echo "<td style='width: 50%; text-align: center;' valign='top'>";
         // see if the site has Possible Bad Word files
         $possible_bad_words = load_site_possible_bad_words_given_project($this->projectid);
         if (count($possible_bad_words)) {
             echo "<p>";
             echo "<b>" . _("Words in the Site's Possible bad words file:") . "</b><br>";
             echo new_window_link("show_project_possible_bad_words.php?projectid={$this->projectid}", _("Display"));
             echo " | ";
             echo "<a href='show_project_possible_bad_words.php?projectid={$this->projectid}&amp;format=file'>" . _("Download") . "</a>";
             echo "</p>";
         }
         // see if there are P1 (or later) and OCR pages before showing the link.
         // type-in projects may have P1 (or later) pages but no OCR pages
         // and the current show_project_stealth_scannos.php page only works
         // with projects that have OCR text
         if ($exist_pages_in_P1_or_later && $exist_OCR_pages) {
             echo "<p>";
             echo "<b>" . _("Suggestions from diff analysis:") . "</b><br>";
             echo new_window_link("show_project_stealth_scannos.php?projectid={$this->projectid}", _("Display"));
             echo " | ";
             echo "<a href='show_project_stealth_scannos.php?projectid={$this->projectid}&amp;format=file'>" . _("Download") . "</a>";
             echo "</p>";
         }
         echo "</td>";
         echo "</tr>";
         echo "</table>";
         echo "</td>";
         echo "</tr>";
     }
     echo "<tr>";
     echo "<td class='label' style='text-align: center;' colspan='2'>";
     echo _("Project Dictionary - Word Lists");
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td colspan='2'>";
     echo "<table width='100%'>";
     echo "<tr>";
     echo "<td class='label' style='text-align: center;'>" . _("Good Words") . "</td>";
     echo "<td class='label' style='text-align: center;'>" . _("Bad Words") . "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td style='width: 50%;'>";
     echo "<textarea class='mono' name='good_words' cols='40' rows='20'>{$goodWordData}</textarea>";
     echo "</td>";
     echo "<td style='width: 50%;'>";
     echo "<textarea class='mono' name='bad_words' cols='40' rows='20'>{$badWordData}</textarea>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td colspan='2' style='text-align: center;'>";
     echo sprintf(_("See the %s for more information on word lists."), new_window_link("../../faq/wordcheck-faq.php", _("WordCheck FAQ")));
     echo "</td>";
     echo "</tr>";
 }