include_once $relPath . 'misc.inc';
// attr_safe(), html_safe()
include_once $relPath . 'Stopwatch.inc';
include_once './post_files.inc';
include_once "./word_freq_table.inc";
require_login();
define("LAYOUT_HORIZ", 1);
define("LAYOUT_VERT", 2);
$datetime_format = _("%A, %B %e, %Y at %X");
$watch = new Stopwatch();
$watch->start();
set_time_limit(0);
// no time limit
$projectid = validate_projectID('projectid', @$_REQUEST['projectid']);
$encWord = $_GET["word"];
$word = decode_word($encWord);
$timeCutoff = get_integer_param($_REQUEST, 'timeCutoff', 0, 0, null);
enforce_edit_authorization($projectid);
// get the correct layout
$default_layout = @$_SESSION["show_good_word_suggestions_detail"]["layout"];
if (is_null($default_layout)) {
    // The normal case for the session's first visit.
    $default_layout = LAYOUT_HORIZ;
} else {
    if ($default_layout === LAYOUT_HORIZ || $default_layout === LAYOUT_VERT) {
        // The normal case for the session's subsequent visits.
    } else {
        // I don't know how this could happen.
        $default_layout = LAYOUT_HORIZ;
        // Alternatively, we could raise an error or warning.
    }
include_once $relPath . 'stages.inc';
include_once $relPath . 'misc.inc';
// attr_safe(), html_safe()
include_once $relPath . 'LPage.inc';
include_once $relPath . 'Project.inc';
include_once $relPath . 'slim_header.inc';
include_once './post_files.inc';
include_once "./word_freq_table.inc";
require_login();
define("LAYOUT_HORIZ", 1);
define("LAYOUT_VERT", 2);
set_time_limit(0);
// no time limit
$projectid = validate_projectID('projectid', @$_GET['projectid']);
$encWord = @$_GET["word"];
$word = rtrim(decode_word($encWord));
enforce_edit_authorization($projectid);
// get the right layout
$layout = array_get($_GET, "layout", @$_SESSION["show_word_context"]["layout"]);
if (empty($layout)) {
    $layout = LAYOUT_HORIZ;
}
$_SESSION["show_word_context"]["layout"] = $layout;
$wordInstances = get_integer_param($_GET, 'wordInstances', 20, 0, null);
// $frame determines which frame we're operating from
// 'master' - we're the master frame
//  'left'  - we're the left frame with the text
// 'right'  - we're the right frame for the image
$frame = get_enumerated_param($_GET, 'frame', 'master', array('master', 'left', 'right'));
if ($frame == "master") {
    slim_header_frameset(_("Word Context"));
$pm = array_get($_REQUEST, "pm", $pguser);
if (!user_is_a_sitemanager() && !user_is_proj_facilitator()) {
    $pm = $pguser;
}
// $frame determines which frame we're operating from
//     none - we're the master frame
//   'left' - we're the left frame with the text
//  'right' - we're the right frame for the context info
// 'update' - not a frame at all - process the incoming data
$frame = get_enumerated_param($_REQUEST, 'frame', 'master', array('master', 'left', 'right', 'update'));
if ($frame == "update") {
    $newProjectWords = array();
    foreach ($_POST as $key => $val) {
        if (preg_match("/cb_(projectID[0-9a-f]{13})_(\\d+)/", $key, $matches)) {
            $projectid = $matches[1];
            $word = decode_word($val);
            if (!is_array(@$newProjectWords[$projectid])) {
                $newProjectWords[$projectid] = array();
            }
            array_push($newProjectWords[$projectid], $word);
        }
    }
    foreach ($newProjectWords as $projectid => $projectWords) {
        $words = load_project_good_words($projectid);
        $words = array_merge($words, $projectWords);
        save_project_good_words($projectid, $words);
    }
    $frame = "left";
}
if ($frame == "master") {
    slim_header_frameset(_("Manage Suggestions"));
function decode_address(&$in)
{
    $addr = false;
    $pre = $start = $name = $inptr = "";
    decode_lwsp($in);
    $start = $inptr = $in;
    $pre = decode_word($inptr);
    while ($pre != false) {
        $name .= $pre;
        $pre = false;
        $pre = decode_word($inptr);
        if ($pre != false) {
            $name .= ' ';
        }
    }
    decode_lwsp($inptr);
    $addr = decode_mailbox($in);
    return $addr;
}