require_login();
// check to see if the user is authorized to be here
if (!(user_is_a_sitemanager() || user_is_proj_facilitator())) {
    die("You are not authorized to use this form.");
}
// fetch any data sent our way.
$action = array_get($_REQUEST, "action", "list");
$language = array_get($_REQUEST, "language", "");
$language = urldecode($language);
$list_type = array_get($_REQUEST, "list_type", "");
$cutoff = array_get($_REQUEST, "cutoff", 25);
$lang_match = array_get($_REQUEST, "lang_match", "primary");
$title = _("Show common words from project word lists");
output_header($title, NO_STATSBAR);
echo "<h1>{$title}</h1>";
$display_list = _handle_action($action, $list_type, $language, $cutoff, $lang_match);
if ($display_list) {
    echo "<p>" . _("This page can assist building site-wide Good and Bad word lists. The concept is that if a word appears on a significant portion of project word lists it is a good candidate for a site-wide word list. Given a project language and word list type it will create a combined list of words from all projects for that language. The results list indicates out of the projects with word lists, what percentage of those contain the word.") . "</p>";
    echo "<p>" . _("The results list is just a recommendation and should be vetted by subject matter experts (native language speakers, PFs, etc) before being added to a site-wide word list.") . "</p>";
    // show create form
    echo "<form action='show_common_words_from_project_word_lists.php' method='post'>";
    echo "<input type='hidden' name='action' value='show'>";
    echo "<table>";
    echo "<tr>";
    echo "<td>" . _("Project Languages:") . "</td>";
    echo "<td><select name='language'>";
    // load all project languages
    $res = mysql_query("\n        SELECT language, count(language)\n        FROM projects\n        GROUP BY language\n    ");
    $used_languages = array();
    while (list($language, $language_count) = mysql_fetch_row($res)) {
        if (strpos($language, " with ")) {
    // We want the fields of $_POST to be unescaped strings,
    // so we strip the slashes.
    $_POST = array_map('stripslashes', $_POST);
}
// fetch any data sent our way. word_string will only
// come in via a POST but the others may come in
// via a GET as well so we use $_REQUEST for them
$action = array_get($_REQUEST, "action", "list");
$list_type = array_get($_REQUEST, "list_type", "");
$language = array_get($_REQUEST, "language", "");
$word_string = array_get($_POST, "word_string", "");
$title = _("Manage Site Word Lists");
$extra_args['css_data'] = _get_stylesheet();
output_header($title, NO_STATSBAR, $extra_args);
echo "<h1>{$title}</h1>";
$display_list = _handle_action($action, $list_type, $language, $word_string);
if ($display_list) {
    echo "<h2>" . _("Create a new site word list") . "</h2>";
    // show create form
    echo "<form action='manage_site_word_lists.php' method='post'>";
    echo "<input type='hidden' name='action' value='create'>";
    echo "<table>";
    echo "<tr>";
    echo "<td>" . _("Language") . ":</td>";
    echo "<td><select name='language'>";
    foreach ($lang_list as $langArray) {
        $language = $langArray["lang_name"];
        echo "<option value='{$language}'>{$language}</option>";
    }
    echo "</select>";
    echo "</td>";