<?php
/**
 *  p2 書き込みフォーム (PC, 携帯)
 * （2013/06/06 lib/post_form.inc.php から移動）
 */

/**
 * @access  public
 * @return  string  HTML
 */
function getPostFormHtml($host, $bbs, $key, $ttitle_en, $rescount)
{
    global $_conf, $STYLE; // readonly
    global $htm, $hs; // readonly
    // $htm['src_fix'], $htm['be2ch'], $htm['title_need_be'], $htm['maru_kakiko']
    // $hs['mail'], $hs['FROM']
    global $time_for_post, $res_disabled_at, $MESSAGE_hs, $wrap, $msg_cols_at, $sage_cb_ht, $on_check_sage, $mail_size_at, $name_size_at; // readonly
    global $ptitle, $submit_value; // readonly
    global $popup, $newthread_hidden_ht, $readnew_hidden_ht, $resable_msg_ht; // for read
    
    $csrfid = P2Util::getCsrfId();

    $k_br_ht = '';
    $kakiko_on_js_ht = '';
    if (UA::isIPhoneGroup() || UA::isPC()) {
        // 2013/06/13 iPhone Safari, AndroidのChromeで onKeyup を拾うのを確認した。
        $kakiko_on_js_ht = ' onFocus="adjustTextareaRows(this, 2);" onKeyup="adjustTextareaRows(this, 2);'
            . sprintf(" autoSavePostForm('%s', '%s', '%s');", $host, $bbs, $key) . '"';
    // 携帯
    } else {
        $k_br_ht = '<br>';
    }

    $subject_ht             = isset($htm['subject'])        ? $htm['subject'] : '';
    $popup_hs               = isset($popup)                 ? hs($popup) : '';
    $newthread_hidden_ht    = isset($newthread_hidden_ht)   ? $newthread_hidden_ht : '';
    $readnew_hidden_ht      = isset($readnew_hidden_ht)     ? $readnew_hidden_ht : '';

    $ttitle_en_hs = hs($ttitle_en);

    // 文字コード判定用文字列を先頭に仕込むことでmb_convert_variables()の自動判定を助ける
    $post_form_htm = <<<EOP
<form id="resform" method="POST" action="{$_conf['post_php']}?guid=ON" accept-charset="{$_conf['accept_charset']}" onsubmit="disableSubmit(this)">
	{$htm['resform_ttitle']}
	{$htm['orig_msg']}

	<input type="hidden" name="detect_hint" value="◎◇">
	{$subject_ht}
	{$htm['maru_kakiko']} 名前： <input id="FROM" name="FROM" type="text" value="{$hs['FROM']}"{$name_size_at}>{$k_br_ht} 
	 E-mail : <input id="mail" name="mail" type="text" value="{$hs['mail']}"{$mail_size_at}{$on_check_sage}>
	{$sage_cb_ht}{$k_br_ht}
	<textarea id="MESSAGE" name="MESSAGE" rows="{$STYLE['post_msg_rows']}"{$msg_cols_at} wrap="{$wrap}"{$res_disabled_at}{$kakiko_on_js_ht}>{$MESSAGE_hs}</textarea>{$k_br_ht}
	<input id="submit" type="submit" name="submit" value="{$submit_value}"{$res_disabled_at}{$htm['title_need_be']} onClick="setHiddenValue(this);">
	{$htm['be2ch']}
	<br>
	{$htm['src_fix']}

	<input type="hidden" name="bbs" value="{$bbs}">
	<input type="hidden" name="key" value="{$key}">
	<input type="hidden" name="time" value="{$time_for_post}">

	<input type="hidden" name="host" value="{$host}">
	<input type="hidden" name="popup" value="{$popup_hs}">
	<input type="hidden" name="rescount" value="{$rescount}">
	<input type="hidden" name="ttitle_en" value="{$ttitle_en_hs}">
	<input type="hidden" name="csrfid" value="{$csrfid}">
	{$newthread_hidden_ht}{$readnew_hidden_ht}
	{$_conf['k_input_ht']}

	<span id="status_post_form" style="font-size:10pt;"></span>\n
EOP;

    if (UA::isPC() || UA::isIPhoneGroup()) {
        $post_form_htm .= <<<EOP
<script type="text/javascript">
<!--
var messageObj = document.getElementById('MESSAGE');
if (!messageObj.value) {
	hukkatuPostFormByCookie('{$host}', '{$bbs}', '{$key}');
}
-->
</script>\n
EOP;
    }

    if (!empty($GLOBALS['brazil'])) {
        $post_form_htm .= $resable_msg_ht . "\n";
    }

    $post_form_htm .= "</form>\n";
    
    return $post_form_htm;
}

/*
 * Local Variables:
 * mode: php
 * coding: cp932
 * tab-width: 4
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */
// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:
