<form method="post" name="compose" enctype="multipart/form-data" action="<?php echo Horde::url('compose.php?uniq=' . uniqid(rand())) ?>">

<?php
$count = 0;
if (!isset($error) || !is_array($error)) {
    $numerrors = 0;
} else {
    $numerrors = count($error);
}
$errorsleft = $numerrors;
if ($numerrors > 0) {
    for ($k = 0; $k < count($error); $k++) {
        if (isset($ignoreall)) {
            $ignores = explode(',', $ignoreall);
            if (member($error[$k][0],$ignores)) $errorsleft--;
        }
    }
}
$i = 0;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr class="header">
    <td colspan="8" class="header">
      <b>
<?php if ($errorsleft > 0): ?>
        <?php echo _("Spell Checker") ?> - <i><?php echo $errorsleft ?> <?php if ($errorsleft > 1) echo _("spelling errors"); else echo _("spelling error"); ?></i>
<?php else: ?>
        <?php echo _("Spell check complete") ?> - <?php echo _("No spelling errors") ?>
<?php endif; ?>
      </b>
    </td>
  </tr>
<?php
while ($count < $prefs->getValue('num_words') && $i < $numerrors) {
    if (!isset($error) || !is_array($error)) {
        echo _("Spell check complete");
        break;
    }
    if (isset($ignoreall)) {
        $ignores = explode(',', $ignoreall);
        if (member($error[$i][0],$ignores))
            $includeword = 0;
        else
            $includeword = 1;
	}
    else
        $includeword = 1;
    if ($includeword) {
?>

  <tr class="item">
    <td class="item"><?php echo _("Correct") ?></td>
    <td colspan="3" nowrap="nowrap">
<?php
    $offset = $error[$i][1];
    $word = $error[$i][0];
    $alt = $error[$i][2];
    echo '<font color="ff0000">"' . htmlspecialchars($word) . '"</font>';
    echo _(" in ");
    $context = highlight_error(htmlspecialchars($word), htmlspecialchars($f_message), htmlspecialchars($offset));
    if ($context != '')
        echo "<span class=\"fixed\">$context</span>";
    else
        echo _("none");
?>

    </td>
    <td><b><i><?php echo _("Change"); ?></i></b></td>
    <td><b><i><?php echo _("Change All"); ?></i></b></td>
    <td><?php echo _("Ignore") ?></td>
    <td><?php echo _("Ignore All") ?></td>
  </tr>
  <tr>
    <td class="item"><b><?php echo _("Suggestions") ?></b></td>
    <td class="item">
      <input type="hidden" name="oldword[<?php echo $count ?>]" value="<?php echo htmlspecialchars($word) ?>" />
      <input type="hidden" name="wordoffset[<?php echo $count ?>]" value="<?php echo htmlspecialchars($offset) ?>" />
      <select name="subs[<?php echo $count ?>]" onchange="change_selected(<?php echo $count ?>);">
<?php
if ($alt != '') {
    $checkedval = 3;
    $altwords = explode(', ', $alt);
    for ($j = 0; $j < count($altwords); $j++) {
        echo '<option value="' . htmlspecialchars($altwords[$j]) . '">' . htmlspecialchars($altwords[$j]) . '</option>';
    }
} else {
    $checkedval = 3;
    echo '<option value="0">' . _("No suggestions") . '</option>';
}
?></select>
    </td>
    <td class="item"><b><?php
        if (!empty($alt)) {
            echo _("or");
        } else {
            echo _("Replace with:");
        }
?></b></td>
    <td class="item"><input type="text" name="subtext[<?php echo $count ?>]" size="12" onchange="change_selected(<?php echo $count ?>);" /></td>
    <td class="item"><input type="radio" value="1" name="opt[<?php echo $count ?>]" <?php if ($checkedval == 1) echo 'checked="checked"'; ?> /></td>
    <td class="item"><input type="radio" value="2" name="opt[<?php echo $count ?>]" <?php if ($checkedval == 2) echo 'checked="checked"'; ?> /></td>
    <td class="item"><input type="radio" value="3" name="opt[<?php echo $count ?>]" <?php if ($checkedval == 3) echo 'checked="checked"'; ?> /></td>
    <td class="item"><input type="radio" value="4" name="opt[<?php echo $count ?>]" <?php if ($checkedval == 4) echo 'checked="checked"'; ?> /></td>
  </tr>
<?php
        $count++;
    }
    $i++;
}
?>
  <tr class="item">
    <td colspan="8" class="item">
      <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SPELL_CHECK_CANCEL ?>'; document.compose.submit();" value="<?php echo _("Cancel") ?>" /><i>&nbsp;<?php echo _("(Discard all changes and return to the compose screen.)") ?></i>
    </td>
  </tr>
<?php if ($actionID == SPELL_CHECK_FORWARD || $errorsleft == 0): ?>
  <tr class="item">
    <td colspan="8" class="item">
      <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SPELL_CHECK_DONE ?>'; document.compose.submit();" value="<?php echo _("Done") ?>" /><i>&nbsp;<?php echo _("(Return to the compose screen after applying all changes made thus far.  Changes on the current screen will NOT be applied.)") ?></i>
    </td>
  </tr>
<?php endif; ?>
<?php if ($errorsleft > 0): ?>
  <tr class="item">
    <td colspan="8" class="item">
      <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SPELL_CHECK_FORWARD ?>'; document.compose.submit();" value="<?php echo _("Next") ?>" /><i>&nbsp;<?php echo _("(Apply these changes and move to next screen.)") ?></i>
    </td>
  </tr>
<?php endif; ?>
  <tr><td colspan="8">&nbsp;</td></tr>
  <tr class="header"><td colspan="8" class="header"><b><?php echo _("Corrected Text") ?></b></td></tr>
  <tr><td colspan="8" class="item">
    <div class="fixed"><pre><?php echo htmlspecialchars($f_newmsg . $f_message) ?></pre></div>
  </td></tr>
</table>

<!-- Maintain lots of state -->
<input type="hidden" name="actionID" value="" />
<input type="hidden" name="spellcheck" value="" />
<input type="hidden" name="popup" value="<?php echo htmlspecialchars(Horde::getFormData('popup', '')); ?>" />
<input type="hidden" name="index" value="<?php if (isset($index)) echo htmlspecialchars($index); ?>" />
<?php if (isset($is_reply)): ?><input type="hidden" name="is_reply" value="1" /><?php endif; ?>
<?php if (isset($in_reply_to)): ?><input type="hidden" name="in_reply_to" value="<?php echo htmlspecialchars($in_reply_to) ?>" /><?php endif; ?>
<?php if (isset($references)): ?><input type="hidden" name="references" value="<?php echo htmlspecialchars($references) ?>" /><?php endif; ?>
<input type="hidden" name="oldmsg" value="<?php echo htmlspecialchars($f_oldmsg) ?>" />
<input type="hidden" name="message" value="<?php echo htmlspecialchars($f_message) ?>" />
<input type="hidden" name="newmsg" value="<?php echo htmlspecialchars($f_newmsg) ?>" />
<input type="hidden" name="ignoreall" value="<?php echo htmlspecialchars($f_ignoreall) ?>" />
<input type="hidden" name="changeall" value="<?php echo htmlspecialchars(Horde::getFormData('changeall')) ?>" />
<input type="hidden" name="identity" value="<?php echo htmlspecialchars(Horde::getFormData('identity')) ?>" />
<input type="hidden" name="from" value="<?php echo htmlspecialchars(Horde::getFormData('from')) ?>" />
<input type="hidden" name="subject" value="<?php if (isset($subject)) echo htmlspecialchars($subject) ?>" />
<input type="hidden" name="reloaded" value="1" />
<?php if (Horde::getFormData('save_sent_mail') == 'on'): ?>
<input type="hidden" name="save_sent_mail" value="on" />
<input type="hidden" name="sent_mail_folder" value="<?php echo htmlspecialchars(Horde::getFormData('sent_mail_folder')) ?>" />
<?php endif; ?>
<?php if (Horde::getFormData('request_return_receipt') == 'on'): ?>
<input type="hidden" name="request_return_receipt" value="on" />
<?php endif; ?>

<!-- To: addresses -->
<?php if (!empty($f_to)): ?><input type="hidden" name="to" value="<?php echo htmlspecialchars(Horde::getFormData('to')) ?>" /><?php endif; ?>
<?php if (!empty($f_to_new)): ?><input type="hidden" name="to_new" value="<?php echo htmlspecialchars(Horde::getFormData('to_new')) ?>" /><?php endif; ?>
<?php if (!empty($f_to_list) && is_array($f_to_list)): ?>
<?php foreach ($f_to_list as $search => $found): ?>
<input type="hidden" name="to_list[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($found) ?>" />
<?php if (isset($f_to_field) && isset($f_to_field[$search])): ?>
<input type="hidden" name="to_field[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($f_to_field[$search]) ?>" />
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

<!-- Cc: addresses -->
<?php if (!empty($f_cc)): ?><input type="hidden" name="cc" value="<?php echo htmlspecialchars(Horde::getFormData('cc')) ?>" /><?php endif; ?>
<?php if (!empty($f_cc_new)): ?><input type="hidden" name="cc_new" value="<?php echo htmlspecialchars(Horde::getFormData('cc_new')) ?>" /><?php endif; ?>
<?php if (!empty($f_cc_list) && is_array($f_cc_list)): ?>
<?php foreach ($f_cc_list as $search => $found): ?>
<input type="hidden" name="cc_list[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($found) ?>" />
<?php if (isset($f_cc_field) && isset($f_cc_field[$search])): ?>
<input type="hidden" name="cc_field[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($f_cc_field[$search]) ?>" />
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

<!-- Bcc: addresses -->
<?php if (!empty($f_bcc)): ?><input type="hidden" name="bcc" value="<?php echo htmlspecialchars(Horde::getFormData('bcc')) ?>" /><?php endif; ?>
<?php if (!empty($f_bcc_new)): ?><input type="hidden" name="bcc_new" value="<?php echo htmlspecialchars(Horde::getFormData('bcc_new')) ?>" /><?php endif; ?>
<?php if (!empty($f_bcc_list) && is_array($f_bcc_list)): ?>
<?php foreach ($f_bcc_list as $search => $found): ?>
<input type="hidden" name="bcc_list[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($found) ?>" />
<?php if (isset($f_bcc_field) && isset($f_bcc_field[$search])): ?>
<input type="hidden" name="bcc_field[<?php echo htmlspecialchars($search) ?>]" value="<?php echo htmlspecialchars($f_bcc_field[$search]) ?>" />
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

<!-- Attachment Form -->
<?php if (isset($_POST['attachments_name']) && is_array($_POST['attachments_name']) && count($_POST['attachments_name']) > 0): ?>
<?php for ($i = 0; $i < count($_POST['attachments_name']); $i++): ?>
<input type="hidden" name="attachments_name[]" value="<?php echo htmlspecialchars($_POST['attachments_name'][$i]) ?>" />
<input type="hidden" name="attachments_size[]" value="<?php echo htmlspecialchars($_POST['attachments_size'][$i]) ?>" />
<input type="hidden" name="attachments_file[]" value="<?php echo htmlspecialchars($_POST['attachments_file'][$i]) ?>" />
<input type="hidden" name="attachments_type[]" value="<?php echo htmlspecialchars($_POST['attachments_type'][$i]) ?>" />
<?php endfor; ?>
<?php endif; ?>

</form>
