<?
if (!defined("_GNUBOARD_")) exit; // °³º° ÆäÀÌÁö Á¢±Ù ºÒ°¡

if ($is_dhtml_editor) {
    include_once("$g4[path]/lib/cheditor.lib.php");
    echo "<script src='$g4[editor_path]/cheditor.js'></script>";
    echo cheditor1('wr_content', $content);
}
?>

<script language="javascript">
// ±ÛÀÚ¼ö Á¦ÇÑ
var char_min = parseInt(<?=$write_min?>); // ÃÖ¼Ò
var char_max = parseInt(<?=$write_max?>); // ÃÖ´ë
</script>

<form name="fwrite" method="post" action="javascript:fwrite_check(document.fwrite);" enctype="multipart/form-data" style="margin:0px;">
<input type=hidden name=null> 
<input type=hidden name=w        value="<?=$w?>">
<input type=hidden name=bo_table value="<?=$bo_table?>">
<input type=hidden name=wr_id    value="<?=$wr_id?>">
<input type=hidden name=sca      value="<?=$sca?>">
<input type=hidden name=sfl      value="<?=$sfl?>">
<input type=hidden name=stx      value="<?=$stx?>">
<input type=hidden name=spt      value="<?=$spt?>">
<input type=hidden name=sst      value="<?=$sst?>">
<input type=hidden name=sod      value="<?=$sod?>">
<input type=hidden name=page     value="<?=$page?>">

<table width="<?=$width?>" align=center cellpadding=0 cellspacing=0><tr><td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<colgroup width=100>
<colgroup width=''>
<tr><td colspan=2 height=2 bgcolor=#b0adf5></td></tr>
<tr><td style='padding-left:20px' colspan=2 height=38 bgcolor=#f8f8f9><strong><?=$title_msg?></strong></td></tr>

<? if ($is_name) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ÀÌ¸§</td>
    <td><input class=ed maxlength=20 size=15 name=wr_name itemname="ÀÌ¸§" required value="<?=$name?>"></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_password) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ÆÐ½º¿öµå</td>
    <td><input class=ed type=password maxlength=20 size=15 name=wr_password itemname="ÆÐ½º¿öµå" <?=$password_required?>></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_email) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ÀÌ¸ÞÀÏ</td>
    <td><input class=ed maxlength=100 size=50 name=wr_email email itemname="ÀÌ¸ÞÀÏ" value="<?=$email?>"></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_homepage) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ È¨ÆäÀÌÁö</td>
    <td><input class=ed size=50 name=wr_homepage itemname="È¨ÆäÀÌÁö" value="<?=$homepage?>"></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_notice || $is_html || $is_secret || $is_mail) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ¿É¼Ç</td>
    <td><? if ($is_notice) { ?><input type=checkbox name=notice value="1" <?=$notice_checked?>>°øÁö&nbsp;<? } ?>
        <? if ($is_html) { ?>
            <? if ($is_dhtml_editor) { ?>
            <input type=hidden value="html1" name="html">
            <? } else { ?>
            <input onclick="html_auto_br(this);" type=checkbox value="<?=$html_value?>" name="html" <?=$html_checked?>><span class=w_title>html</span>&nbsp;
            <? } ?>
        <? } ?>
        <? if ($is_secret) { ?>
            <? if ($is_admin || $is_secret==1) { ?>
            <input type=checkbox value="secret" name="secret" <?=$secret_checked?>><span class=w_title>ºñ¹Ð±Û</span>&nbsp;
            <? } else { ?>
            <input type=hidden value="secret" name="secret">
            <? } ?>
        <? } ?>
        <? if ($is_mail) { ?><input type=checkbox value="mail" name="mail" <?=$recv_email_checked?>>´äº¯¸ÞÀÏ¹Þ±â&nbsp;<? } ?></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_category) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ºÐ·ù</td>
    <td><select name=ca_name required itemname="ºÐ·ù"><option value="">¼±ÅÃÇÏ¼¼¿ä<?=$category_option?></select></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ Á¦¸ñ</td>
    <td><input class=ed style="width:100%;" name=wr_subject itemname="Á¦¸ñ" required value="<?=$subject?>"></td></tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<tr>
    <td style='padding-left:20px;'>¡¤ ³»¿ë</td>
    <td style='padding:5 0 5 0;'>
        <? if ($is_dhtml_editor) { ?>
            <?=cheditor2('fwrite', 'wr_content', '100%', '350');?>
        <? } else { ?>
        <table width=100% cellpadding=0 cellspacing=0>
        <tr>
            <td width=50% align=left valign=bottom>
                <span style="cursor: pointer;" onclick="textarea_decrease('wr_content', 10);"><img src="<?=$board_skin_path?>/img/up.gif"></span>
                <span style="cursor: pointer;" onclick="textarea_original('wr_content', 10);"><img src="<?=$board_skin_path?>/img/start.gif"></span>
                <span style="cursor: pointer;" onclick="textarea_increase('wr_content', 10);"><img src="<?=$board_skin_path?>/img/down.gif"></span></td>
            <td width=50% align=right><? if ($write_min || $write_max) { ?><span id=char_count></span>±ÛÀÚ<?}?></td>
        </tr>
        </table>
        <textarea id=wr_content name=wr_content class=tx style='width:100%; word-break:break-all;' rows=10 itemname="³»¿ë" required 
        <? if ($write_min || $write_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?}?>><?=$content?></textarea>
        <? if ($write_min || $write_max) { ?><script language="javascript"> check_byte('wr_content', 'char_count'); </script><?}?>
        <? } ?>
        </td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>

<? if ($is_link) { ?>
<? for ($i=1; $i<=$g4[link_count]; $i++) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ ¸µÅ© #<?=$i?></td>
    <td><input type='text' class=ed size=50 name='wr_link<?=$i?>' itemname='¸µÅ© #<?=$i?>' value='<?=$write["wr_link{$i}"]?>'></td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>
<? } ?>

<? if ($is_file) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'><table cellpadding=0 cellspacing=0><tr><td style=" padding-top: 10px;">¡¤ ÆÄÀÏ <span onclick="add_file();" style='cursor:pointer; font-family:tahoma; font-size:12pt;'>+</span> <span onclick="del_file();" style='cursor:pointer; font-family:tahoma; font-size:12pt;'>-</span></td></tr></table></td>
    <td style='padding:5 0 5 0;'><table id="variableFiles" cellpadding=0 cellspacing=0></table><?// print_r2($file); ?>
        <script language="JavaScript">
        var flen = 0;
        function add_file(delete_code)
        {
            var upload_count = <?=(int)$board[bo_upload_count]?>;
            if (upload_count && flen >= upload_count)
            {
                alert("ÀÌ °Ô½ÃÆÇÀº "+upload_count+"°³ ±îÁö¸¸ ÆÄÀÏ ¾÷·Îµå°¡ °¡´ÉÇÕ´Ï´Ù.");
                return;
            }

            var objTbl;
            var objRow;
            var objCell;
            if (document.getElementById)
                objTbl = document.getElementById("variableFiles");
            else
                objTbl = document.all["variableFiles"];

            objRow = objTbl.insertRow(objTbl.rows.length);
            objCell = objRow.insertCell(0);

            objCell.innerHTML = "<input type='file' class=ed size=32 name='bf_file[]' title='ÆÄÀÏ ¿ë·® <?=$upload_max_filesize?> ÀÌÇÏ¸¸ ¾÷·Îµå °¡´É'>";
            if (delete_code)
                objCell.innerHTML += delete_code;
            else
            {
                <? if ($is_file_content) { ?>
                objCell.innerHTML += "<br><input type='text' class=ed size=50 name='bf_content[]' title='¾÷·Îµå ÀÌ¹ÌÁö ÆÄÀÏ¿¡ ÇØ´ç µÇ´Â ³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä.'>";
                <? } ?>
                ;
            }

            flen++;
        }

        <?=$file_script; //¼öÁ¤½Ã¿¡ ÇÊ¿äÇÑ ½ºÅ©¸³Æ®?>

        function del_file()
        {
            // file_length ÀÌÇÏ·Î´Â ÇÊµå°¡ »èÁ¦µÇÁö ¾Ê¾Æ¾ß ÇÕ´Ï´Ù.
            var file_length = <?=(int)$file_length?>;
            var objTbl = document.getElementById("variableFiles");
            if (objTbl.rows.length - 1 > file_length)
            {
                objTbl.deleteRow(objTbl.rows.length - 1);
                flen--;
            }
        }
        </script></td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_trackback) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ Æ®·¢¹éÁÖ¼Ò</td>
    <td><input class=ed size=50 name=wr_trackback itemname="Æ®·¢¹é" value="<?=$trackback?>">
        <? if ($w=="u") { ?><input type=checkbox name="re_trackback" value="1">ÇÎ º¸³¿<? } ?></td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<? if ($is_norobot) { ?>
<tr>
    <td style='padding-left:20px; height:30px;'>¡¤ <?=$norobot_str?></td>
    <td><input class=ed type=input size=10 name=wr_key itemname="ÀÚµ¿µî·Ï¹æÁö" required>&nbsp;&nbsp;* ¿ÞÂÊÀÇ ±ÛÀÚÁß <font color="red">»¡°£±ÛÀÚ¸¸</font> ¼ø¼­´ë·Î ÀÔ·ÂÇÏ¼¼¿ä.</td>
</tr>
<tr><td colspan=2 height=1 bgcolor=#e7e7e7></td></tr>
<? } ?>

<tr><td colspan=2 height=1 bgcolor=#000000></td></tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td width="100%" height="30" background="<?=$board_skin_path?>/img/write_down_bg.gif"></td>
</tr>
<tr>
    <td width="100%" align="center" valign="top">
        <input type=image id="btn_submit" src="<?=$board_skin_path?>/img/btn_write.gif" border=0 accesskey='s'>&nbsp;
        <a href="./board.php?bo_table=<?=$bo_table?>"><img id="btn_list" src="<?=$board_skin_path?>/img/btn_list.gif" border=0></a></td>
</tr>
</table>

</td></tr></table>
</form>


<script language="javascript">
<?
// °ü¸®ÀÚ¶ó¸é ºÐ·ù ¼±ÅÃ¿¡ '°øÁö' ¿É¼ÇÀ» Ãß°¡ÇÔ
if ($is_admin) 
{
    echo "
    if (typeof(document.fwrite.ca_name) != 'undefined')
    {
        document.fwrite.ca_name.options.length += 1;
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].value = '°øÁö';
        document.fwrite.ca_name.options[document.fwrite.ca_name.options.length-1].text = '°øÁö';
    }";
} 
?>

with (document.fwrite) {
    if (typeof(wr_name) != "undefined")
        wr_name.focus();
    else if (typeof(wr_subject) != "undefined")
        wr_subject.focus();
    else if (typeof(wr_content) != "undefined")
        wr_content.focus();

    if (typeof(ca_name) != "undefined")
        if (w.value == "u")
            ca_name.value = "<?=$write[ca_name]?>";
}

function html_auto_br(obj) {
    if (obj.checked) {
        result = confirm("ÀÚµ¿ ÁÙ¹Ù²ÞÀ» ÇÏ½Ã°Ú½À´Ï±î?\n\nÀÚµ¿ ÁÙ¹Ù²ÞÀº °Ô½Ã¹° ³»¿ëÁß ÁÙ¹Ù²ï °÷À»<br>ÅÂ±×·Î º¯È¯ÇÏ´Â ±â´ÉÀÔ´Ï´Ù.");
        if (result)
            obj.value = "html2";
        else
            obj.value = "html1";
    }
    else
        obj.value = "";
}

function fwrite_check(f) {
    var s = "";
    if (s = word_filter_check(f.wr_subject.value)) {
        alert("Á¦¸ñ¿¡ ±ÝÁö´Ü¾î('"+s+"')°¡ Æ÷ÇÔµÇ¾îÀÖ½À´Ï´Ù");
        return;
    }

    if (s = word_filter_check(f.wr_content.value)) {
        alert("³»¿ë¿¡ ±ÝÁö´Ü¾î('"+s+"')°¡ Æ÷ÇÔµÇ¾îÀÖ½À´Ï´Ù");
        return;
    }

    if (char_min > 0 || char_max > 0) {
        var cnt = parseInt(document.getElementById('char_count').innerHTML);
        if (char_min > 0 && char_min > cnt) {
            alert("³»¿ëÀº "+char_min+"±ÛÀÚ ÀÌ»ó ¾²¼Å¾ß ÇÕ´Ï´Ù.");
            return;
        } 
        else if (char_max > 0 && char_max < cnt) {
            alert("³»¿ëÀº "+char_max+"±ÛÀÚ ÀÌÇÏ·Î ¾²¼Å¾ß ÇÕ´Ï´Ù.");
            return;
        }
    }

    if (typeof(f.wr_key) != "undefined") {
        if (hex_md5(f.wr_key.value) != md5_norobot_key) {
            alert("ÀÚµ¿µî·Ï¹æÁö¿ë »¡°£±ÛÀÚ°¡ ¼ø¼­´ë·Î ÀÔ·ÂµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
            f.wr_key.focus();
            return;
        }
    }

    <?
    if ($is_dhtml_editor) {
        echo cheditor3('wr_content');
        echo "if (!document.getElementById('wr_content').value) { alert('³»¿ëÀ» ÀÔ·ÂÇÏ½Ê½Ã¿À.'); return; } ";
    }
    ?>

    document.getElementById('btn_submit').disabled = true;
    document.getElementById('btn_list').disabled = true;

    f.action = "./write_update.php";
    f.submit();
}
</script>