# Ir-i-BBS   -  interface for PC
# ------------------------------
#   Copyright (c) 1999 by Irao Computer System, All rights reserved.
#

my $copyright_pc = "Copyright (c) 1999 by Irao";
#ここまで変更厳禁

sub set_pc_body_color {
    while(($k, $v) = each %body) {
        $body_attr{$k} = qq/$k="$v"/ if ($v ne "");
    }

    $body_attributes = join(" ", values %body_attr);
    $body_attributes = ($body_attributes =~ /^\s*$/)? "" : " $body_attributes";

    &value_to_attribute(*caption_table_color, "bgcolor");
    &value_to_attribute(*content_table_color, "bgcolor");
    &value_to_attribute(*subject_color, "color");
    &value_to_attribute(*caption_head_color, "bgcolor");
    &value_to_attribute(*title_back_color, "bgcolor");
}

sub value_to_attribute {
    local (*value, $name) = @_;
    return if ($value eq "");
    $value = qq/ ${name}="$value"/;
}

sub view_pc_head {
    my ($arg) = @_;
    my ($cookie_name, $cookie_mail, $cookie_url, $cookie_pass);

    require $ir_i_def_pl if ($imchr_title);

    $cookie_name="";
    $cookie_mail="";
    $cookie_url="";
    $cookie_pass="";
    
    $cookie_name = qq/ value="$COOKIE{'name'}"/ if($COOKIE{'name'} ne "");
    $cookie_mail = qq/ value="$COOKIE{'email'}"/ if($COOKIE{'email'} ne "");
    $cookie_url = qq/ value="$COOKIE{'webpage'}"/ if($COOKIE{'webpage'} ne "");
    $cookie_pass = qq/ value="$COOKIE{'seed'}"/ if($COOKIE{'seed'} ne "");

    $bbs_about = ${bbs_local} . '?a=about';

    my $rettop = (($ret_local) && ($ret_local !~ m|^\s*$|))? $ret_local : '';
    if ($rettop) {
        $rettop = qq|<a href="$rettop">トップに戻る</a>|;
    } else {
        $rettop = qq|トップに戻る|;
    }
    my $counterStr = $pc_counter_front_str . $a_count . $pc_counter_back_str
    if ($pc_counter_mode and $enable_counter);
=cut
    $buffer =<<"EOB";
<center>$counterStr$headlines
<table border=1 cellspacing=0><tr><th$caption_head_color>
<form action="$bbs_local" method=POST><input type=hidden name=kan value="漢字">
<input type=hidden name=a value=regist>名前</th><th$caption_head_color>
E-mail</th><th$caption_head_color>Webpage</th></tr><tr align=center>
<td><input type=text size=10 name=name maxlength=14$cookie_name></td>
<td><input type=text size=20 name=email maxlength=36$cookie_mail></td>
<td><input type=text size=20 name=webpage maxlength=48$cookie_url></td></tr>
<tr><th$caption_head_color>題名</th><th$caption_head_color>本文</th>
<th$caption_head_color>削除パスワード</th></tr>
<tr align=center><td><input type=text size=20 maxlength=16 name=subject></td>
<td rowspan=2><textarea name=message rows=4 cols=30></textarea></td>
<td><input type=password size=10 maxlength=8 name=pass$cookie_pass></td>
<tr align=center><td><a href="$bbs_about">この掲示板の概要</a><br>
<br>$rettop</td><td>
<br><input type=submit value="書込み"> <input type=reset value="クリア"></form>
EOB
=cut

	$buffer =<<"EOB";
<center>$counterStr$headlines
<table border=1 cellspacing=0>
<tr><th$caption_head_color>
<form action="$bbs_local" method=POST>
<input type=hidden name=kan value="漢字">
<input type=hidden name=a value=regist>名前</th>
<th$caption_head_color>E-mail</th>
<th$caption_head_color>Webpage</th>
<th$caption_head_color>削除パスワード</th>
</tr>
<tr align=center>
<td><input type=text size=15 name=name maxlength=20$cookie_name></td>
<td><input type=text size=20 name=email maxlength=40$cookie_mail></td>
<td><input type=text size=25 name=webpage maxlength=60$cookie_url></td>
<td><input type=password size=10 maxlength=8 name=pass$cookie_pass></td>
</tr>
<tr>
<th colspan=2$caption_head_color>題名</th>
<th colspan=2$caption_head_color>本文</th>
</tr>
<tr align=center>
<td colspan=2><input type=text size=30 maxlength=40 name=subject></td>
<td rowspan=2 colspan=2><textarea name=message rows=5 cols=40></textarea></td>
<tr align=center><td><a href="$bbs_about">この掲示板の概要</a><br>
<br>$rettop</td><td>
<br><input type=submit value="書込み"> <input type=reset value="クリア"></form>
EOB

    my ($add);
    if (($save_log) && (-e $bbs_log_file)) {
        $add = '<option value=logmode>ログ';
    }
    if ($arg) {
#        my $next = $start + $page_max;
        $buffer .=<<"EOB";
<form action="$bbs_local" method=POST>
<select name=a><option value=find>検索
<option value=delete>削除<option value=select>修正$add</select>
<input type=hidden name=start value=$start>
<input type=submit value="実行"></form>
EOB
    }
$buffer .= '</td></tr></table></center><a name="list"></a><hr>';
}

sub view_pc_body {
    my ($line, $add) = @_;
    unless ($line) {
        $buffer .= "<p><big>投稿はありません</big></p><br>\n";
        return;
    }
    my ($subject, $name, $mail, $web, $message, $date, $host,
                    $addr, $agent, $pass, $unkey) = split("\t", $line);
    chomp $unkey;
    $date = &conv_date($date);
    my $addition = "";
    if (defined $add) {
        if ($add eq 'ColorTest') {
            $subject_color = 'js[subject]';
            $content_table_color = 'js[content]';
            $caption_table_color = 'js[caption]';
        } elsif ($add < 0) {
            $addition = <<"EOA";
<input type="radio" name="mod" value="$unkey">
EOA
        } else {
            $addition = <<"EOA";
<input type="checkbox" name="remove" value="$unkey">
EOA
        }
    }
    my $xjmsn = "";
    if ($agent =~ m|J-skyweb|) {
        $agent =~ /\(([^;]+).*\)/;
        $xjmsn = $1;
    } elsif ($agent =~ m|J-PHONE/[\d.]+/(J-[a-zA-Z]+[0-9]+)|i) {
        $xjmsn = $1;
    }
    my $env = &is_imode($agent, $xjmsn);
    $envimg = "$env.gif";
    $envimg = "ezweb.gif" if ($env eq "ez");
    $envimg = "mopera.gif" if ($env eq "paldio");
    $envimg = "doti.gif" if ($env eq "astel");
    $envalt = "i-mode" if ($env eq "imode");
    $envalt = "browser-phone" if ($env eq "paldio");
    $envalt = "dot.i" if ($env eq "astel");
    $envalt = "PC" if ($env eq "pc");
    $envalt = "EZWeb" if ($env eq "ez");
    $envalt = "J-sky" if ($env eq "jsky");
    $mail = '[<a href="mailto:' . $mail . '">Mail</a>]' if ($mail ne "");
    my $url = "";
    $url = '[<a href="' . $web . '">URL</a>]' if ($web ne "");

    $message = &conv_imchr($message);
    $subject = &conv_imchr($subject);
    $name = &conv_imchr($name);

    $message = &conv_jschr($message);
    $subject = &conv_jschr($subject);
    $name = &conv_jschr($name);

    my ($hostaddr) = "";
    $hostaddr= "[$host/$addr]" if ($print_ip);
    $buffer .= <<"EOB";
<table border=1 width="90%" align=center><tr><td$caption_table_color>
<table width="100%" border=0 cellpadding=2 cellspacing=0>
<tr><td align=left valign=center>
$addition<font size="+1"$subject_color><b>$subject</b></font></td>
<td valign=center>by <b>$name</b> <small>$mail $url</small></td>
<td align=right valign=center>
 <small>$date</small></td></tr></table><tr><td$content_table_color>
<img src="$envimgpath$envimg" align=right alt=$envalt>
<p>$message</p>
<br clear=all><table width="100%" border=0 cellpadding=2 cellspacing=0>
<tr><td align=right valign=center><small>$hostaddr $agent</small>
</td></tr></table></td></tr></table><br>
EOB
}

sub view_pc_foot {
    my ($nf, $called) = @_;
    my ($add);
    my $next = $start + $page_max;
    my $prev = $start - $page_max;
    $prev = 0 if ($prev < 0);
    if ($called == 1) {
        $add = '<input type=hidden name=a value=delete>';
    } elsif ($called == 2) {
        $add = '<input type=hidden name=a value=select>';
    }
    if ($FORM{'mode'} =~ /^log$/i) { # 完全にdelete/selectと排他的
        $add = '<input type=hidden name=mode value=log>';
        $add .= "<input type=hidden name=num value=$FORM{'num'}>"
            if ($FORM{'num'});
    }
    $buffer .= qq|<hr><center><form action="$bbs_local#list" method=POST>${add}|;
    if ($start != 0) {
        $buffer .= qq/<input type=submit name="pos:$prev" value="前ページ">/;
    }
    $buffer .= qq/　　<input type=submit name="pos:0" value="更新">　　/;
    if ($nf) {
        $buffer .= qq/<input type=submit name="pos:$next" value="次ページ">/;
    }
    $buffer .= qq|</form></center>|;
    &$output_buffer;
}

sub view_pc_nums {
    my ($st, $en, $al) = @_;
    $buffer .= "新着順${st}～${en}件／全${al}件";
    $buffer .= "　(検索式; <B>${global_logic_formula}</B>)"
        if ($global_logic_formula);
    $buffer .= "<br>";
}

sub view_log_pc_head {
    my ($arg) = @_;

    require $ir_i_def_pl if ($imchr_title);

    $bbs_about = $bbs_local . '?a=about';

    my $rettop = (($ret_local) && ($ret_local !~ m|^\s*$|))? $ret_local : '';
    if ($rettop) {
        $rettop = qq|<a href="$rettop">トップに戻る</a>|;
    } else {
        $rettop = 'トップに戻る';
    }
    $buffer =<<"EOB";
<center>$headlines
<table border=1 cellspacing=0>
<tr><th $caption_head_color>
過去ログ参照モード
</th></tr>
<tr align=center><td>
<a href="$bbs_about">この掲示板の概要</a>　
$rettop　
<a href="$bbs_local">通常モードに戻る</a><br>
EOB

    if ($arg) {
        $buffer .=<<"EOB";
<form action="$bbs_local" method=POST>
<input type=hidden name=mode value=log>
<input type=hidden name=start value=$start>
<input type=submit name="act:find" value="検索する">　
<select name=num><option value="">標準
<option value=10>10<option value=25>25
<option value=50>50<option value=100>100
</select>件　
<input type=submit name="pos:0" value="表\示更新">
</form>
EOB
    }
$buffer .= '</td></tr></table></center><a name="list"></a><hr>';
}

sub view_log_pc {
    $view_head = 'view_log_pc_head';
    $view_body = 'view_pc_body';
    $view_foot = 'view_pc_foot';
}

sub delete_pc_head {

    require $ir_i_def_pl if ($imchr_title);
    $buffer =<<"EOB";
<center>$headlines<form action="$bbs_local" method=POST>
<input type=hidden name="a" value="remove"><table border=1 cellspacing=0>
<tr><th$caption_head_color>削除パスワード</th><td rowspan=2>
<input type=submit value="削除"> <input type=reset value="クリア"></td>
<td rowspan=2><a href="$bbs_local">削除モードから抜ける</a></td></tr>
<tr align=center><td><input type=password size=10 name=pass maxlength=8>
</td></tr></table></center><a name="list"></a><hr>
EOB
}

sub delete_pc_body {
    my ($line) = @_;
    &view_pc_body($line, 1);
}

sub delete_pc_foot {
    my ($nf) = @_;
    $buffer .= "</form>";
    &view_pc_foot($nf, 1);
}

sub delete_pc {
    $view_head = 'delete_pc_head';
    $view_body = 'delete_pc_body';
    $view_foot = 'delete_pc_foot';
    &view;
}

sub select_pc_head {
    require $ir_i_def_pl if ($imchr_title);
    $buffer = <<"EOB";
<center>$headlines<form action="$bbs_local" method=POST>
<input type=hidden name="a" value="modify"><table border=1 cellspacing=0>
<tr><th$caption_head_color>削除パスワード</th><td rowspan=2>
<input type=submit value="修正"> <input type=reset value="クリア"></td>
<td rowspan=2><a href="$bbs_local">修正モードから抜ける</a></td></tr>
<tr align=center><td><input type=password size=10 name=pass maxlength=8>
</td></tr></table></center><a name="list"></a><hr>
EOB
}

sub select_pc_body {
    my ($line) = @_;
    &view_pc_body($line, -1);
}

sub select_pc_foot {
    my ($nf) = @_;
    $buffer .= "</form>";
    &view_pc_foot($nf, 2);
}

sub select_pc {
    $view_head = 'select_pc_head';
    $view_body = 'select_pc_body';
    $view_foot = 'select_pc_foot';
    &view;
}

sub modify_pc {
    my ($subject, $name, $email, $web, $message, $pass, $num) = &modify();
    $message =~ s/<br>/\n/gi;
    map {
        s/\&/\&amp;/g;
        s/\"/\&quot;/g;
        s/>/\&gt;/g;
        s/</\&lt;/g;
    } ($subject, $name, $message);
    $buffer = <<"EOB";
<center>$headlines
<table border=1 cellspacing=0><tr><th$caption_head_color>
<form action="$bbs_local" method=POST><input type=hidden name=mod value="$num">
<input type=hidden name=pass value="$pass">
<input type=hidden name=kan value="漢字">
<input type=hidden name=a value=modify>名前</th><th$caption_head_color>
E-mail</th><th$caption_head_color>Webpage</th></tr><tr align=center>
<td><input type=text size=10 name=name maxlength=14 value="$name"></td>
<td><input type=text size=20 name=email maxlength=36 value="$email"></td>
<td><input type=text size=20 name=webpage maxlength=48 value="$web"></td></tr>
<tr><th$caption_head_color>題名</th><th$caption_head_color>本文</th>
<th$caption_head_color>削除パスワード</th></tr><tr align=center><td>
<input type=text size=20 maxlength=16 name=subject value="$subject"></td>
<td rowspan=2><textarea name=message rows=4 cols=30>$message</textarea></td>
<td><input type=password size=10 maxlength=8 name=pnew value="$pass"></td>
<tr align=center><td><a href="$ret_local">トップに戻る</a></td><td>
<br><input type=submit value="修正"></form>
EOB

    $buffer .= "</td></tr></table></center><hr>";
    &$output_buffer;
    exit;
}

sub about_pc {
    $about_html_data = &load_about;
    $buffer = <<"EOA";
$about_html_data
<!--NoTopLink--><!--NoAdmin-->
EOA
    &$output_buffer;
    exit;
}

sub error_pc {
    my ($s) = @_;
    
    $buffer = <<"EOB";
<p>$s</p><!--NoAdmin-->
EOB
    &$output_buffer;
}

sub set_master_mode_pc {
    my $bbs_color = $bbs_local . '?a=ch_color' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_about = $bbs_local . '?a=ch_about' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_init = $bbs_local . '?a=ch_init' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $link_init = <<"EOL" if ($initial_setup ne "pass");
<ul>
<li><a href="$bbs_color">掲示板の配色の変更</a>
<li><a href="$bbs_about">掲示板の概要の変更</a>
<li><a href="$bbs_init">掲示板の設定の変更</a>
</ul>
EOL

    $buffer = <<"EOB";
マスターキー設定<br>
$link_init
<form method="POST" action="$bbs_local">
<input type="hidden" name="a" value="set_master">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}">
<table border=1 cellspacing=0>
<tr><th$caption_head_color rowspan=2>変更</th>
<th$caption_head_color>新パスワード</th>
<td><input type="password" name="new1"></td></tr>
<tr><th$caption_head_color>新パスワード</th>
<td><input type="password" name="new2"><br>
（確認のためもう一度）</td></tr>
<tr align=center><td colspan=3><input type="submit" value="実行">　　　
<input type="reset" value="クリア">
</td></tr></table>
</form><!--NoTopLink--><!--NoAdmin-->
EOB
    &$output_buffer;
    exit;
}


sub search_body_pc {
    my ($add);
    if ($FORM{'mode'} =~ /^log$/i) {
        $add = '<input type=hidden name=mode value=log>';
        $add .= "<input type=hidden name=num value=$FORM{'num'}>"
            if ($FORM{'num'});
    }
    $buffer = <<"EOB";
記事の検索<form method="POST" action="$bbs_local"><center>
<table border=1 cellspacing=0><tr><th$caption_head_color>検索語句</th>
<td><input type="text" name="q"></td></tr><tr><th$caption_head_color>検索モード
</th><td><select name="l"><option value="and">AND 検索
<option value="or">OR 検索</select></td></tr></table>
<input type="submit" value="検索"> <input type="reset" value="クリア">
$add</form></center><a href="$bbs_local">掲示板に戻る</a>
<!--NoTopLink--><!--NoAdmin-->
EOB
    &$output_buffer;
    exit;
}

sub search_pc_head {
    my ($arg, $data) = @_;
    &$view_head($arg);
#    &view_pc_head($arg);
    $buffer .= "<P><CENTER><B>$data</B>の検索結果</CENTER></P>\n";
}

sub search_pc_foot {
    my ($nf, $key, $logic) = @_;
    my $next = $start + $page_max;
    my $add;
    if ($FORM{'mode'} =~ /^log$/i) {
        $add = '<input type=hidden name=mode value=log>';
        $add .= "<input type=hidden name=num value=$FORM{'num'}>"
            if ($FORM{'num'});
    }
=cut
    if ($nf) {
        $buffer .= <<"EOB";
<hr>
<form action="$bbs_local" method=POST><!--input type=hidden name=start value=$next-->
<input type=hidden name=q value="$key"><input type=hidden name=l value="$logic">
$add<!--input type=submit value="次のページ"-->
</form>
EOB
    }
=cut
    $buffer .= qq|<hr><center><form action="$bbs_local#list" method=POST>${add}|;
    $buffer .= qq|<input type=hidden name=q value="$key">|;
    $buffer .= qq|<input type=hidden name=l value="$logic">|;
    if ($start != 0) {
        $buffer .= qq/<input type=submit name="pos:$prev" value="前ページ">/;
    }
    $buffer .= qq/　　<input type=submit name="pos:0" value="先頭">　　/;
    if ($nf) {
        $buffer .= qq/<input type=submit name="pos:$next" value="次ページ">/;
    }
    $buffer .= qq|</form></center>|;

    &$output_buffer;
}

sub get_webhost {
    my ($arg) = @_;
    return 'http://' . $ENV{'SERVER_NAME'} . '/'
        if ($arg =~ m#^\s*$#);
    return $arg;
}

sub set_init_mode_pc {
    my ($def_pass) = $FORM{'new1'} if ($FORM{'action'} eq 'set_master');

    $init_exist = &load_init($init_file);

    if ($ac_public == 1) {
        $ac_mark = 2 if ($ac_mark == 0);
    }
    my $bbs_admin = $bbs_local . '?a=ch_master' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_color = $bbs_local . '?a=ch_color' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_about = $bbs_local . '?a=ch_about' .
                    '&authorize=' . $COOKIE{'authorize'};
    $bbs_url = 'http://' . $ENV{'SERVER_NAME'} . $ENV{'SCRIPT_NAME'}
        if ($bbs_url =~ /^\s*$/);
    $bbs_local = $ENV{'SCRIPT_NAME'}
        if ($bbs_local =~ /^\s*$/);

    $ret_url = &get_webhost($ret_url);
    $ret_imode = &get_webhost($ret_imode);
    $ret_ez = &get_webhost($ret_ez);
    $ret_jsky = &get_webhost($ret_jsky);
    $ret_pc = &get_webhost($ret_pc);
    
    my (@dom, $srv, $link_init);
    @dom = split(/\./, $ENV{'SERVER_NAME'});
    if (length($dom[$#dom]) != 2) {
        splice(@dom, 0, $#dom - 1);
    } else {
        splice(@dom, 0, $#dom - 2);
    }
    $srv = join(".", @dom);

    $email_admin = 'webmaster@' . $srv
        if ($email_admin =~ /^\s*$/);
    $link_init = <<"EOL" if ($initial_setup ne "init");
<ul>
<li><a href="$bbs_admin">管理パスワードの変更</a>
<li><a href="$bbs_color">掲示板の配色の変更</a>
<li><a href="$bbs_about">掲示板の概要の変更</a>
</ul>
EOL
    my (@help_array) = (
        '<p>　記事数がこの値を超えると、古いものから削除されます</p>',
        '<p>　クッキーに使用される識別用の文字列です</p>',
        '<p>　指定は相対パスでも可能です</p>',
        '<p>　サーバーによって異なる場合があります</p>' . 
            '<p>　詳しくはサーバー管理者にお尋ねください</p>',
        '<p>　通知メールのFrom欄に指定されるアドレスです</p>'.
            '<p>　空白にすると管理者メールアドレスになります</p>',
        '<p>　オンにすると絵文字の説明をALT属性に設定します</p>',
        '<p>　オンにするとi-modeの絵文字をEZwebのアイコンに変換します</p>' .
            '</p>　一部表示が崩れる場合があります',
        '<p>　うまく投稿できない場合は、この指定をオフにしてください</p>',
        '<p>　セキュリティなどの都合で、オフにすることができます</p>',
        '<p>　環境別アイコン画像を置いた場所です</p>' .
            '<p>　相対または絶対で指定してください</p>' .
            '<p>　指定しない場合は.cgiと同じパスにあるとみなします</p>',
        '<p>　タイトルとフォームの間に表\示される文字列です</p>' .
            '<p>　広告などを入れます(タグも使えます)</p>',
        '<p>　投稿通知メールを送信しない記事を設定します</p>' .
            '<p>　名前とメールアドレスは空白か半角カンマで区切って' .
            '複数指定できます</p>',
        '<p>　Cookieの保存期間を時間単位で入力します</p>' .
            '<p>　この設定で決められている時間だけPassが保存されます</p>',
        '<p>　i-mode, J-skyで「削除Pass」が入力されていないときの挙動を' .
            '設定します</p>',
        '<p>　EZwebのアクセス制御機能の設定です</p><p>　詳しくは、' .
            '<a href=\"http://www.irao.com/irao/ir-i-bbs/faq.html\" ' .
            'target=\"_blank\">Ir-i-BBS - よくある質問と回答</a>' .
            'をお読みください</p>'
    );
    my ($script) = &make_helper_script(@help_array);
    $script .= &make_layer_script;
    $extra_header = <<"EOE";
<script type="text/javascript" language="JavaScript"><!--
function setBase(theForm, urlDef) {
  BaseUrl = prompt("戻り先URLを一斉に変更；", urlDef);
  if (BaseUrl != null) {
    theForm.ret_url.value = BaseUrl;
    theForm.ret_ez.value = BaseUrl;
    theForm.ret_imode.value = BaseUrl;
    theForm.ret_jsky.value = BaseUrl;
    theForm.ret_pc.value = BaseUrl;
  }
}
$script
//--></script>
<meta http-equiv="Content-Type" content="text/html; charset=SHIFT_JIS">
EOE

    $buffer =<<"EOB";
掲示板の各種設定<br>
$link_init
EOB

    $headlines =~ s/\&/\&amp;/g;
    $headlines =~ s/\"/\&quot;/g;
    $headlines =~ s/</\&lt;/g;
    $headlines =~ s/>/\&gt;/g;
    
    $template =<<'EOT';
!B1CS0![C2W200]*項目,[W300]*設定,[W50]*備考
[R11]*全般,*汎用タイトル,{IT;title;same;32}
*i-mode{B}ブラウザホン,{IT;imode_title;same;20}
*J-skyweb,{IT;jsky_title;same;20}{B}マイリンク{B}{IT;jsky_mylink_title;same;20}{B}ステーション非対応機{B}{IR;jsky_station_title_control;1;;same}マイリンクのみ表示　　　{IR;jsky_station_title_control;0;;same}両方表示
*EZweb,{IT;ezweb_title;same;20}
*ドットi,{IT;astel_title;same;20}
*管理者メールアドレス,{IT;email_admin;same;32}
*記録する最大記事数,{IT;regist_max;same;4},{A;javascript:HelpWin(0);ヘルプ}
*過去ログを保存,{IR;save_log;1;;same}する　　　{IR;save_log;0;;same}しない
*掲示板URL,{IT;bbs_url;same;32}
*削除パス未入力時は{B}(i-mode%2C J-sky),　{IR;del_pass_mode;0;;same}フォームを再表示{B}　{IR;del_pass_mode;1;;same}自動生成して表示する{B}　{IR;del_pass_mode;2;;same}文句なくエラー表示,{A;javascript:HelpWin(13);ヘルプ}
*アクセスカウンタ,{IR;enable_counter;1;;same}有効　　　{IR;enable_counter;0;;same}無効
[R6]*悪戯防止,*入室制限,制限　{IR;limit_mode;1;;same}有効　　　{IR;limit_mode;0;;same}無効{B}入室パスワード　{IT;limit_pass;same;16}
*IP制限,IPが{B}　{IT;restrict_ip_list;same;24}{B}のホストのみを{B}　{IR;restrict_mode;0;;same}書込禁止{B}　{IR;restrict_mode;1;;same}入室禁止{B}　{IR;restrict_mode;2;;same}書込許可{B}する
*書込制限,{IR;write_limit;0;;same}全員　　　{IR;write_limit;master;;same}管理者のみ
*投稿サイズ,{IT;restrict_size;same;4}kB
*記事の改行数,{IT;restrict_newline;same;4}個
*禁止語句,{IT;restricted_words;same;32}
[R5]*戻り先URL{B}{IB;;一斉変更;;;setBase(this.form%2C '$ret_url')},*絶対パス表記,{IT;ret_url;same;32}
*i-mode,{IT;ret_imode;same;32},[R4]{A;javascript:HelpWin(2);ヘルプ}
*EZweb,{IT;ret_ez;same;32}
*J-sky,{IT;ret_jsky;same;32}
*PC,{IT;ret_pc;same;32}
[R5]*最大表示数{B}(1頁あたり),*i-mode,{IT;page_max_i;same;4}件{B}自動調整{IR;imode_auto;1;;same}する　　　{IR;imode_auto;0;;same}しない{B}調整サイズ{IT;imode_auto_size;same;4}kB
*EZweb,{IT;page_max_ez;same;4}件{B}自動調整{IR;ez_auto;1;;same}する　　　{IR;ez_auto;0;;same}しない{B}調整サイズ{IT;ez_auto_size;same;4}kB
*EZweb[選択画面],{IT;page_max_ez_ce;same;4}件
*J-sky,{IT;page_max_j;same;4}件{B}自動調整{IR;jsky_auto;1;;same}する　　　{IR;jsky_auto;0;;same}しない{B}調整サイズ{IT;jsky_auto_size;same;4}kB
*PC,{IT;page_max_pc;same;4}件
[R8]*投稿通知,*投稿通知を,{IR;email_send;1;;same}する　　　{IR;email_send;0;;same}しない
*送信方法,{IR;email_method;1;;same}sendmailを使う{B}パス{IT;sendmail;same;32}{B}{IR;email_method;-1;;same}blat.exeを使う{B}パス{IT;blat;same;32}{B}{IR;email_method;0;;same}SMTPに接続する{B}サーバ{IT;smtp_server;same;32}　ポート{IT;smtp_port;same;4},{A;javascript:HelpWin(3);ヘルプ}
*宛先,{IT;email_to;same;32}
*送信者メールアドレス,{IT;email_from;same;32},{A;javascript:HelpWin(4);ヘルプ}
*題名,{IT;email_subj;same;24}
*通知しない記事,名前{IT;except_names;same;32}{B}　{S;or}{B}メールアドレス{IT;except_adrs;same;32}{B}　{S;or}{B}IP{IT;except_ip_list;same;24},{A;javascript:HelpWin(11);ヘルプ}
*通知間隔,{IT;interval_send;same;4}分
*通知禁止時間帯,{IR;prohibit_time_zone;1;;same}有効　　　{IR;prohibit_time_zone;0;;same}無効{B}(24時制){IT;prohibit_time_zone_begin;same;4}時から{IT;prohibit_time_zone_end;same;4}時までは通知しない
[R2]*絵文字,*説明を表示,{IR;imchr_title;1;;same}する　　　{IR;imchr_title;0;;same}しない,{A;javascript:HelpWin(5);ヘルプ}
*EZwebアイコンに変換,{IR;imchr_ezicon;1;;same}する　　　{IR;imchr_ezicon;0;;same}しない,{A;javascript:HelpWin(6);ヘルプ}
[R5]*Cookie,*掲示板ID,{IT;bbs_id;same;10},{A;javascript:HelpWin(1);ヘルプ}
*認証[管理人],{IT;cook_author_master;same;4}時間,[R3]{A;javascript:HelpWin(12);ヘルプ}
*認証[入室時],{IT;cook_author_enter;same;4}時間
*管理パス登録時,{IT;cook_initial;same;4}時間
*EZwebアクセス記録,{IT;cookDaysEz;same;4}日
[R5]*PC,*Referer,Refererのチェックを{B}{IR;referer_check;1;;same}する　　　{IR;referer_check;0;;same}しない{B}PocketIEの時はチェックを{B}{IR;no_check_pocket_ie;0;;same}する　　　{IR;no_check_pocket_ie;1;;same}しない,{A;javascript:HelpWin(7);ヘルプ}
*IPを表示,{IR;print_ip;1;;same}する　　　{IR;print_ip;0;;same}しない,{A;javascript:HelpWin(8);ヘルプ}
*カウンタ,{IR;pc_counter_mode;1;;same}表示　　　{IR;pc_counter_mode;0;;same}非表示{B}{IT;pc_counter_front_str;same;20}「カウンタ値」{IT;pc_counter_back_str;same;20}
*画像へのパス,{IT;env_img_path;$envimgpath;32},{A;javascript:HelpWin(9);ヘルプ}
*見出し,{T;head_lines;$headlines;30;4},{A;javascript:HelpWin(10);ヘルプ}
[R7]*携帯/PHS,*検索モード,{IR;term_logic_mode;1;;same}詳細　　　{IR;term_logic_mode;0;;same}簡易
*カウンタ,{IR;mobile_counter_mode;1;;same}表示　　　{IR;mobile_counter_mode;0;;same}非表示{B}{IT;mobile_counter_front_str;same;16}「カウンタ値」{IT;mobile_counter_back_str;same;16}
*i-mode{B}J-skyweb,投稿は{B}{IR;imode_post_button;1;;same}ボタン表示　　　{IR;imode_post_button;0;;same}リンク
*ドットi,「Referer」を確認{B}{IR;check_astel_referer;1;;same}する　　　{IR;check_astel_referer;0;;same}しない{B}保存ページからの投稿を{B}{IR;allow_astel_savepage;1;;same}許可する　　　{IR;allow_astel_savepage;0;;same}拒否する
*DoCoMo PHS{B}ブラウザフォン,「Referer」を確認{B}{IR;check_paldio_referer;1;;same}する　　　{IR;check_paldio_referer;0;;same}しない
*EZweb,メニューに「管理人に連絡する」を表示{B}{IR;contact_admin;1;;same}する　　　{IR;contact_admin;0;;same}しない{B}「Referer」を送信{B}{IR;send_referer_ez;1;;same}する　　　{IR;send_referer_ez;0;;same}しない
*デッキアクセス制御,{IR;ac_valid;1;;same}有効　　　{IR;ac_valid;0;;same}無効{B}　{IR;ac_mark;1;;same}MARKABLE{B}　{IR;ac_mark;2;;same}PUBLIC{B}　{IR;ac_mark;3;;same}不許可{B}ACCESSDOMAIN　{IT;ac_domain;same;16}{B}ACCESSPATH　{IT;ac_path;same;16},{A;javascript:HelpWin(14);ヘルプ}
%C[C4]{IS;;設定}　　　{IE;;クリア}
EOT
    if (($ENV{'HTTP_USER_AGENT'} =~ /MSIE\s+(\d)/) && ($1 >= 4)) {
        &make_switch_dhtml;
        if ($FORM{'disable_dhtml'}) {
            &make_table;
        } else {
            &make_table_ie4;
            &make_style;
            &make_hint_script;
        }
    } elsif (($ENV{'HTTP_USER_AGENT'} =~ m|Mozilla/(\d)|) && ($1 >= 4)) {
        &make_switch_dhtml;
        if ($FORM{'disable_dhtml'}) {
            &make_table;
        } else {
            &make_table_nc4;
            &make_style;
            &make_hint_script;
        }
    } else {
        &make_table;
    }

    $buffer .= <<"EOB";
<br>
<!--NoTopLink--><!--NoAdmin-->
EOB

    &$output_buffer;
    exit;
}

sub set_color_mode_pc {
    my ($def_pass) = $FORM{'new1'} if ($FORM{'action'} eq 'set_master');

    $init_exist = &load_init($init_file);

    ($caption_table = $caption_table_color) =~ s/^[^=]+="(.*)"$/$1/;
    ($content_table = $content_table_color) =~ s/^[^=]+="(.*)"$/$1/;
    ($subject_table = $subject_color) =~ s/^[^=]+="(.*)"$/$1/;
    ($caption_head = $caption_head_color) =~ s/^[^=]+="(.*)"$/$1/;
    ($title_back = $title_back_color) =~ s/^[^=]+="(.*)"$/$1/;

    my ($output_data, @output_lines);
    $test_article =<<"EOT";
記事のテスト	irao	irao\@irao.com	http://www.irao.com	記事のテスト表\示はJavaScriptを使用しております &#63893;	2000<y>01<mo>01<d>土<w>00<h>00<mi>	fwisp-ext4.docomo.ne.jp	210.153.84.70	DoCoMo/1.0/P501i	BkWKw8NORM1D2	1U597848237
EOT
    &view_pc_body($test_article, 'ColorTest');
    $buffer =<<"EOB";
<font color=navy>■</font>フォームのテスト<form>
<center><table border=1 cellspacing=0><tr><th js[form]>
項目</th></tr><tr align=center>
<td><input type=text size=10 name=name maxlength=14></td></tr>
<tr align=center><td><input type=button value="ボタン"></td></tr></table>
</center></form>
<font color=navy>■</font>記事表\示のテスト<form>
$buffer
<small>表\示はイメージであり一部異なる場合があります</small><br>
<!--NoTopLink--><!--NoAdmin-->
EOB
    $buffer = &output_buffer_pc('NoOutput');
    $output_data = <<"EOD";
<!-- ir-i-bbs $version --><div align=right><form>
<input type="button" value="閉じる" onClick="window.close()"></form></div>
<font color=navy>■</font>タイトル表\示テスト
$buffer
EOD
    $output_data =~ s/\"/\\"/g; #"
    $output_data =~ s|/|\",\"/|g;
    $output_data =~ s/js\[([^\]]+)\]/\",$1,\"/g;
    @output_lines = split("\n", $output_data);
    foreach (@output_lines) {
        chomp $_;
        $_ = "  " . 'writeln("' . $_ . '");' . "\n";
    }
    $output_data = join("", @output_lines);
    my (@help_array) = (
        '<p>　 BODYエレメントの属性値です</p>' .
            '<p>　属性名に対応する属性値を書くことができます</p>' .
            '<p>　空欄にするとその属性は指定されません</p>',
        '<p>　 BODYエレメントの属性値です</p>' .
            '<p>　「属性名=属性値」と書くと、任意の属性を追加できます</p>' .
            '<p>　空白で区切って複数指定できます</p>',
        '<p>　投稿記事の配色設定です</p>',
        '<p>　掲示板の投稿フォームの項目欄の背景色です</p>',
        '<p>　掲示板のタイトルの背景色です</p>',
        '<p>　カラー端末用の BODYエレメントの属性値です</p>' .
            '<p>　属性名に対応する属性値を書くことができます</p>' .
            '<p>　空欄にするとその属性は指定されません</p>'
    );
    my ($script) = &make_helper_script(@help_array);

    $extra_header = <<"EOE";
<script type="text/javascript" language="JavaScript"><!--
function open_test_page(theForm) {
 var nw = window.open("", "_blank", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1");
 with (nw.document) {
  open();
  if (theForm.text.value != "") fgColor = theForm.text.value;
  writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">');
  writeln("<html><head><title>$title 配色テスト<","/title><", "/head>");
  write("<bo", "dy");
  if (theForm.text.value != "")
    write(" text=\\"", fgColor, "\\"");
  if (theForm.bgcolor.value != "") {
    bgColor = theForm.bgcolor.value;
    write(" bgcolor=\\"", bgColor, "\\"");
  }
  if (theForm.link.value != "") {
    linkColor = theForm.link.value;
    write(" link=\\"", linkColor, "\\"");
  }
  if (theForm.vlink.value != "") {
    vlinkColor = theForm.vlink.value;
    write(" vlink=\\"", vlinkColor, "\\"");
  }
  if (theForm.alink.value != "") {
    alinkColor = theForm.alink.value;
    write(" alink=\\"", alinkColor, "\\"");
  }
  if (theForm.background.value != "")
    write(" background=\\"", theForm.background.value, "\\"");
  writeln(">");
  var caption = "", content = "", subject = "", titleback = "", form = "";
  if (theForm.caption.value != "")
    caption = " bgcolor=\\"" + theForm.caption.value + "\\"";
  if (theForm.content.value != "")
    content = " bgcolor=\\"" + theForm.content.value + "\\"";
  if (theForm.subject.value != "")
    subject = " color=\\"" + theForm.subject.value + "\\"";
  if (theForm.titleback.value != "")
    titleback = " bgcolor=\\"" + theForm.titleback.value + "\\"";
  if (theForm.form.value != "")
    form = " bgcolor=\\"" + theForm.form.value + "\\"";
$output_data
  close();
 }
}
$script
//--></script>
<meta http-equiv="Content-Type" content="text/html; charset=SHIFT_JIS">
EOE

    my $bbs_admin = $bbs_local . '?a=ch_master' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_about = $bbs_local . '?a=ch_about' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_init = $bbs_local . '?a=ch_init' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $link_init = <<"EOL" if ($initial_setup ne "color");
<ul>
<li><a href="$bbs_admin">管理パスワードの変更</a>
<li><a href="$bbs_about">掲示板の概要の変更</a>
<li><a href="$bbs_init">掲示板の設定の変更</a>
</ul>
EOL
    $buffer = <<"EOB";
掲示板の配色設定<br>
$link_init
EOB
    $template =<<'EOT';
^color^!B1CS0![C3W200]*項目,[W300]*設定,[W50]*備考
[R19]*PC,[R7]*BODY,*bgcolor,{IT;bgcolor;%body.same;10},[R6]{A;javascript:HelpWin(0);ヘルプ}
*text,{IT;text;%body.same;10}
*link,{IT;link;%body.same;10}
*vlink,{IT;vlink;%body.same;10}
*alink,{IT;alink;%body.same;10}
*background,{IT;background;%body.same;10}
*その他,{IT;other;same;24},{A;javascript:HelpWin(1);ヘルプ}
[R3]*投稿記事,*題名背景色,{IT;caption;$caption_table;10},[R3]{A;javascript:HelpWin(2);ヘルプ}
*本文背景色,{IT;content;$content_table;10}
*題名文字色,{IT;subject;$subject_table;10}
*フォーム,*題名背景色,{IT;form;$caption_head;10},{A;javascript:HelpWin(3);ヘルプ}
*タイトル,*背景色,{IT;titleback;$title_back;10},{A;javascript:HelpWin(4);ヘルプ}
[R2]*タイトル[文字],*表示,{IR;print_title;1;;same}する　　　{IR;print_title;0;;same}しない
*バージョンを表示,{IR;print_version;1;;same}する　　　{IR;print_version;0;;same}しない
[R5]*タイトル[画像],*表示,{IR;print_gtitle;1;;same}する　　　{IR;print_gtitle;0;;same}しない
*画像,{IT;title_gpath;same;32}
*説明,{IT;title_galt;same;32}
*幅,{IT;title_gwidth;same;32}
*高さ,{IT;title_gheight;same;32}
[R3]*i-mode,[R3]*BODY,*bgcolor,{IT;im_bg;%imode_body.'bgcolor';10},[R3]{A;javascript:HelpWin(5);ヘルプ}
*text,{IT;im_tx;%imode_body.'text';10}
*link,{IT;im_ln;%imode_body.'link';10}
[R3]*J-sky,[R3]*BODY,*bgcolor,{IT;js_bg;%jsky_body.'bgcolor';10},[R3]{A;javascript:HelpWin(5);ヘルプ}
*text,{IT;js_tx;%jsky_body.'text';10}
*link,{IT;js_ln;%jsky_body.'link';10}
%C[C4]{IS;;設定}　　　{IE;;クリア}　　　{IB;;テスト;;;open_test_page(this.form)}
EOT
    &make_table;
$buffer .=<<"EOB";
<br><!--NoTopLink--><!--NoAdmin-->
EOB
    &$output_buffer;
    exit;
}

sub set_about_pc {
    my ($def_pass) = $FORM{'new1'} if ($FORM{'action'} eq 'set_master');

    $init_exist = &load_init($init_file);
    
    $long = &load_about;
    $terminal = 'ez/pseudo';
    $compact = &load_about;
    $topez = "true";
    $eztop = &load_about;

    my $bbs_admin = $bbs_local . '?a=ch_master' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_color = $bbs_local . '?a=ch_color' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $bbs_init = $bbs_local . '?a=ch_init' .
                    '&authorize=' . $COOKIE{'authorize'};
    my $link_init = <<"EOL" if ($initial_setup ne "about");
<ul>
<li><a href="$bbs_admin">管理パスワードの変更</a>
<li><a href="$bbs_color">掲示板の配色の変更</a>
<li><a href="$bbs_init">掲示板の設定の変更</a>
</ul>
EOL
    $buffer = <<"EOB";
掲示板の概要設定<br>
$link_init
<form method="POST" action="$bbs_local">
<input type="hidden" name="a" value="set_about">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}">
<table border=1 cellspacing=0>
<tr><th$caption_head_color width="200">項目</th>
<th$caption_head_color width="300">設定</th></tr>
<tr><th$caption_head_color>EZ用トップ</th>
<td><textarea name="eztop" rows=4 cols=40>$eztop</textarea></td>
</tr>
<tr><th$caption_head_color>携帯用概要</th>
<td><textarea name="compact" rows=4 cols=40>$compact</textarea></td>
</tr>
<tr><th$caption_head_color>PC用概要</th>
<td><textarea name="long" rows=8 cols=40>$long</textarea></td>
</tr>
<tr align=center><td colspan=2><input type="submit" value="設定">
　　　<input type="reset" value="クリア"></td></tr>
</table><br>
</form><!--NoTopLink--><!--NoAdmin-->
EOB
    &$output_buffer;
    exit;
}

sub authorize_pc {
    my ($msg) = @_;
    $buffer = <<"EOB";
$msg<br>
パスワード認証
<form method="POST" action="$bbs_local">
<input type="hidden" name="a" value="authorize">
<input type="hidden" name="next_act" value="$FORM{'next_act'}">
<table border=1 cellspacing=0>
<tr><th$caption_head_color>認証</th>
<th$caption_head_color>パスワード</th>
<td><input type="password" name="pass"></td></tr>
<tr align=center><td colspan=3><input type="submit" value="実行">　　　
<input type="reset" value="クリア">
</td></tr></table>
</form><!--NoTopLink--><!--NoAdmin-->
EOB
    &$output_buffer;
    exit;
}

sub output_buffer_pc {
    my ($flag) = @_;
    my ($header, $htmlhd, $bbs_init, $rettop, $htmlbd);
    local ($footer);

    if ((defined $flag) && ($flag eq "NoOutput")) {
        $title_back_color = 'js[titleback]';
    }

    $bbs_init = $bbs_local . '?a=ch_init';
    $header =<<"EOH";
Content-type: text/html;charset=Shift_JIS

EOH

    $htmlhd =<<"EOH";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head><title>$title</title>
$extra_header</head><!-- ir-i-bbs $version -->
<body$body_attributes>
EOH
    my ($addition, $title_body);
    $addition = " $version" if ($print_version);
    if ($print_title) {
        $title_body =<<"EOT";
<table border=6$title_back_color><tr><td>
<big><strong>$title$addition</strong></big></td>
</tr></table>
EOT
    }
    if ($print_gtitle and $title_gpath) {
        $title_body .= qq/<img src="$title_gpath" alt="$title_galt"/;
        $title_body .= qq/ width="$title_gwidth"/ if ($title_gwidth);
        $title_body .= qq/ height="$title_gheight"/ if ($title_gheight);
        $title_body .= qq/>/;
    }
    $htmlbd =<<"EOH";
<center>$title_body</center>
EOH

    $footer =<<"EOF";
<hr><div align=right><a href="http://www.irao.com/irao/ir-i-bbs/">Ir-i-BBS
$version</a><br>$copyright_pc</div>
EOF
    unless ($buffer =~ s/<!--NoAdmin-->\s*$//) {
        $footer .=<<"EOF";
<a href="$bbs_init">管理人モード</a><br><br>
EOF
    }
    
    $rettop = (($ret_local) && ($ret_local !~ m|^\s*$|))? $ret_local : '';
    $footer .=<<"EOF" if (($rettop) && ($buffer !~ s/<!--NoTopLink-->//));
<a href="$rettop">トップに戻る</a>
EOF
    $footer .= '</body></html>';
    &subst_secure if ($limit_mode);
    $buffer =~ s/<!--\$(\w+)-->/${$1}/og;
    if ((defined $flag) && ($flag eq "NoOutput")) {
        return ($htmlbd . $buffer . $footer);
    }
    if ($FORM{'mode'} =~ /^log$/i) {
        &gzip_output;
    } else {
        print "$header";
    }
    print "$htmlhd";
    print "$htmlbd";
    print "$buffer";
    print "$footer";
}

sub subst_input {
    local ($type, $attribute) = @_;
    $ret = '<input type="';
    if ($type eq "T") {
        $ret .= 'text';
    } elsif ($type eq "R") {
        $ret .= 'radio';
    } elsif ($type eq "C") {
        $ret .= 'checkbox';
    } elsif ($type eq "B") {
        $ret .= 'button';
    } elsif ($type eq "S") {
        $ret .= 'submit';
    } elsif ($type eq "E") {
        $ret .= 'reset';
    }
    $ret .= '"';
    @keys = ('name', 'value', 'size', '', 'onClick', 'disabled');
    @attributes = split (/;/, $attribute);
    foreach $i (0..2,4) {
        if (defined $attributes[$i]) {
            next if ($attributes[$i] =~ /^\s*$/);
            if ($attributes[$i] =~ /^%(\w+)\.(['\w]+)$/) {
                if ($2 eq "same") {
                    $attributes[$i] = '$' . $1 . "{'" . $attributes[0] . "'}";
                } else {
                    $attributes[$i] = '$' . $1 . '{' . $2 . '}';
                }
            }
            if ($attributes[$i] =~ /^same$/) {
                $attributes[$i] = '$' . $attributes[0];
            }
            $attributes[$i] = eval($attributes[$i])
                            if ($attributes[$i] =~ /^\$/);
            $ret .= " $keys[$i]=" . '"' . "$attributes[$i]" . '"';
        }
    }
    if ($attributes[3] !~ /^\s*$/) {
        $a = $attributes[3];
        if ($a =~ /^%(\w+)\.(['\w]+)$/) {
            if ($2 eq "same") {
                $a = '$' . $1 . "{'" . $attributes[0] . "'}";
            } else {
                $a = '$' . $1 . '{' . $2 . '}';
            }
        }
        if ($a =~ /^same$/) {
            $a = '$' . $attributes[0];
        }
        $a = eval($a) if ($a =~ /^\$/);
        $a = 0 if (!(defined $a));
        $ret .= ' checked' if ($a eq $attributes[1]);
    }
    if ($attributes[5] !~ /^\s*$/) {
        $a = $attributes[5];
        $a = ${$a} if ($a =~ /^\$/);
        $ret .= ' disabled' if ($a == 1);
    }
    $ret .= '>';
    $input_entry{$attributes[0]} = 'true' if ($attributes[0]);
    return ($ret);
}

sub subst_a {
    local ($attribute) = @_;
    $ret = '<a href="';

    @attributes = split (/;/, $attribute);
    $ret .= $attributes[0];
    $ret .= '">' . $attributes[1] . '</a>';
    return ($ret);
}

sub subst_textarea {
    local ($attribute) = @_;
    $ret = '<textarea name="';

    @attributes = split (/;/, $attribute);
    $ret .= $attributes[0];
    $ret .= '" cols=' . $attributes[2] . '" rows=' . $attributes[3];
    $ret .= '>' . $attributes[1] . '</textarea>';
    $input_entry{$attributes[0]} = 'true';
    return ($ret);
}

sub subst_strong {
    local ($attribute) = @_;
    $ret = "<strong>$attribute</strong>";
    return ($ret);
}

sub subst_br {
    local ($attribute) = @_;
    $ret = '<br';
    $ret .= ' clear=all' if ($attribute eq "all");
    $ret .= '>';
    return ($ret);
}

sub make_table {
    my ($mode) = 'init';
    local ($o_buffer);
    $o_buffer = '<table';
    if ($template =~ s/^\^(\w+)\^//) {
        $mode = $1;
    }
    if ($template =~ s/^!(\w+)!//) {
        $atrs = $1;
        while ($atrs =~ s/^(B|CS|CP|W)(\d+%?)//) {
            $value = $2;
            if ($1 eq "B") {
                $o_buffer .= ' border=';
            } elsif ($1 eq "CS") {
                $o_buffer .= ' cellspacing=';
            } elsif ($1 eq "CP") {
                $o_buffer .= ' cellpadding=';
            } elsif ($1 eq "W") {
                $o_buffer .= ' width=';
            }
            if ($value =~ /%/) {
                $o_buffer .= '"' . $value . '"';
            } else {
                $o_buffer .= $value;
            }
        }
    }
    $o_buffer .= '>';

    @rows = split(/\n/, $template);
    foreach(@rows){
        $o_buffer .= &purse_comma_table;
    }
    $o_buffer .= '</table>';
    $o_buffer =~ s/(\$\w+)/eval($1)/eg;
    $buffer .=<<"EOB";
<form method="POST" action="$bbs_local">
<input type="hidden" name="a" value="set_$mode">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}">
EOB

    $buffer .= $o_buffer;
    $buffer .= '</form>';
}

sub make_table_nc4 {
    local ($o_buffer);
    $tabular = '<table';
    if ($template =~ s/^!(\w+)!//) {
        $atrs = $1;
        while ($atrs =~ s/^(B|CS|CP|W)(\d+%?)//) {
            $value = $2;
            if ($1 eq "B") {
                $tabular .= ' border=';
            } elsif ($1 eq "CS") {
                $tabular .= ' cellspacing=';
            } elsif ($1 eq "CP") {
                $tabular .= ' cellpadding=';
            } elsif ($1 eq "W") {
                $tabular .= ' width=';
            }
            if ($value =~ /%/) {
                $tabular .= '"' . $value . '"';
            } else {
                $tabular .= $value;
            }
        }
    }
    $tabular .= '>';

    @rows = split(/\n/, $template);
    $capt = shift @rows;
    $capt_bar = &purse_comma_table($capt);
    $counter = 0;
    foreach(@rows){
        next if (/\{IS/ || /\{IE/);
        if (/^\[R\d+\]\*?([^,{]+)/) {
            $o_buffer .= '</table></form></layer>' if ($counter++);
            $o_buffer .= "<layer name=obj${counter} visibility=hide><form name=frm${counter}>${tabular}${capt_bar}";
            $name_entry[$counter - 1] = $1;
        }
        $o_buffer .= &purse_comma_table;
    }
    $o_buffer .= '</table></form></layer>';
    $o_buffer =~ s/(\$\w+)/eval($1)/eg;

    $obuf .=<<"EOO";
<HR><form method="POST" action="$bbs_local" name="formSend">
<input type="hidden" name="a" value="set_init">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}">
<div align=center><big>設定項目一覧</big></div><br>
<TABLE ID="tblTab" BORDER="0" BORDERCOLOR="#C0C0C0" BORDERCOLORLIGHT="#C0C0C0" BORDERCOLORDARK="#C0C0C0" CELLPADDING="0" CELLSPACING="0" width="95%"><TR>
EOO

    for ($i = 0; $i <= $#name_entry; $i++) {
        $j = $i + 1;
        $obuf .=<<"EOO";
<TD height=20 align=center id="tabobj$j" CLASS="tab"><A href="javascript:showLayer('obj$j');" onMouseOver="doHint(event.x,event.y,'hint$j')" onMouseout="stopHint('hint$j')" STYLE="text-decoration: none;">
<FONT SIZE=3> $name_entry[$i] </FONT></a></TD>
EOO
        last if ($i == $#name_entry);
        $obuf .='<td class=hiddentab width=4 height=14><br></td>';
    }
    while(($k, $v) = each %input_entry) {
        $obuf .= qq|<input type="hidden" name="$k" value="">\n|;
    }
    $obuf .=<<"EOO";
</TR></TABLE><BR>
<hr>
<TABLE ALIGN=CENTER><TR ALIGN=CENTER><TD>
<input type=submit value="設定" onClick="setVals()">　　　
<input type=reset value="リセット">
</TD></TR></TABLE></form>
EOO
    $obuf .= '<ilayer name=lay1>';
    $obuf .= $o_buffer;

    $obuf .=<<"EOO";
<layer name=obj0><div align=center>
<p>設定をする項目を選択してください</p><p>初回起動時の設定では、全ての項目の設定を一通り確認してください</p><p>全ての設定が終わったら「設定」ボタンを押して設定完了です</p>
</div></layer></ilayer>
EOO
    for ($i = 0; $i <= $#name_entry; $i++) {
        $j = $i + 1;
        $obuf .=<<"EOO";
<div class=hint id=hint$j>クリックすると $name_entry[$i] の設定画面を表\示します
</div>
EOO
    }
    $buffer .= $obuf;
}

sub make_table_ie4 {
    local ($o_buffer);
    $tabular = '<table';
    if ($template =~ s/^!(\w+)!//) {
        $atrs = $1;
        while ($atrs =~ s/^(B|CS|CP|W)(\d+%?)//) {
            $value = $2;
            if ($1 eq "B") {
                $tabular .= ' border=';
            } elsif ($1 eq "CS") {
                $tabular .= ' cellspacing=';
            } elsif ($1 eq "CP") {
                $tabular .= ' cellpadding=';
            } elsif ($1 eq "W") {
                $tabular .= ' width=';
            }
            if ($value =~ /%/) {
                $tabular .= '"' . $value . '"';
            } else {
                $tabular .= $value;
            }
        }
    }
    $tabular .= '>';

    @rows = split(/\n/, $template);
    $capt = shift @rows;
    $capt_bar = &purse_comma_table($capt);
    $counter = 0;
    foreach(@rows){
        next if (/\{IS/ || /\{IE/);
        if (/^\[R\d+\]\*?([^,{]+)/) {
            $o_buffer .= '</table></span>' if ($counter++);
            $o_buffer .=<<"EOO";
<span id=obj${counter} style="display:none;">${tabular}
EOO
            $name_entry[$counter - 1] = $1;
            $o_buffer .= $capt_bar;
        }
        $o_buffer .= &purse_comma_table;
    }
    $o_buffer .= '</table></span>';
    $o_buffer =~ s/(\$\w+)/eval($1)/eg;

    $obuf .=<<"EOO";
<hr><form method="POST" action="$bbs_local">
<TABLE BORDER="0" BORDERCOLOR="#C0C0C0" BORDERCOLORLIGHT="#C0C0C0" BORDERCOLORDARK="#C0C0C0" CELLPADDING="0" CELLSPACING="0" width="95%">
<TBODY><TR><TD class=tabs>
<TABLE ID="tblTab" BORDER="0" BORDERCOLOR="#C0C0C0" BORDERCOLORLIGHT="#C0C0C0" BORDERCOLORDARK="#C0C0C0" CELLPADDING="0" CELLSPACING="0" width="95%">
<TBODY><input type="hidden" name="a" value="set_init">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}"><TR>
EOO

    for ($i = 0; $i <= $#name_entry; $i++) {
        $j = $i + 1;
        $obuf .=<<"EOO";
<TD ID="tabobj$j" CLASS="tab" onClick="showLayer('obj$j');" height=14 align=center onMouseOver="doHint(event.x,event.y,'hint$j')" onMouseout="stopHint('hint$j')">
<FONT SIZE=2> $name_entry[$i] </FONT></TD>
EOO
        last if ($i == $#name_entry);
        $obuf .='<td class=hiddentab width=4 height=14><br></td>';
    }
    $obuf .=<<"EOO";
</TBODY></TABLE></TD></TR><TR><TD id=tblBody class=tabbody>
EOO
    $obuf .= $o_buffer;
    $obuf .=<<'EOO';
<div align=center><SPAN ID=obj0>
<p>設定をする項目を選択してください</p><p>初回起動時の設定では、全ての項目の設定を一通り確認してください</p><p>全ての設定が終わったら「設定」ボタンを押して設定完了です</p>
</SPAN></div><hr>
<TABLE ALIGN=CENTER><TR ALIGN=CENTER><TD>
<INPUT TYPE=SUBMIT VALUE="設定" CLASS=tabbtn2>　　　
<INPUT TYPE=RESET VALUE="クリア" CLASS=tabbtn2>
</TR></TD></TABLE>
</TD></TR></TBODY></TABLE></form>
EOO
    for ($i = 0; $i <= $#name_entry; $i++) {
        $j = $i + 1;
        $obuf .=<<"EOO";
<div class=hint id=hint$j>クリックすると $name_entry[$i] の設定画面を表\示します
</div>
EOO
    }

    $buffer .= $obuf;
}

sub purse_comma_table {
    local ($_) = @_ if ($#_ >= 0);
    my ($o_buffer);
    $o_buffer .= '<tr';
    if (s/^%(C|R)//) {
        $o_buffer .= ' align=';
        $o_buffer .= 'center' if ($1 eq "C");
        $o_buffer .= 'right' if ($1 eq "R");
    }
    $o_buffer .= '>';
    @cols = split(/,/, $_);
    foreach $col (@cols){
        $col =~ s/%([0-9a-fA-F]{2})/pack("C", hex($1))/eg;
        $out = '<td';
        if($col =~ s/^\[(((C|R|W)(\d+))+)\]//i) {
            $opt = $1;
            $out = '<th$caption_head_color' if ($col =~ s/^\*//);
            $o_buffer .= $out;
            while ($opt =~ s/^(C|R|W)(\d+)//) {
                next if ($2 == 1);
                if ($1 eq "C") {
                    $o_buffer .= " colspan=$2";
                } elsif ($1 eq "R") {
                    $o_buffer .= " rowspan=$2";
                } elsif ($1 eq "W") {
                    $o_buffer .= " width=$2";
                }
            }
        } else {
            $out = '<th$caption_head_color' if ($col =~ s/^\*//);
            $o_buffer .= $out;
        }
        $col =~ s/\{I(T|R|C|B|S|E);([^\}]+)\}/&subst_input($1, $2)/ieg;
        $col =~ s/\{A;([^\}]+)\}/&subst_a($1)/ieg;
        $col =~ s/\{T;([^\}]+)\}/&subst_textarea($1)/ieg;
        $col =~ s/\{B(;[^\}]+)?\}/&subst_br($1)/ieg;
        $col =~ s/\{S;([^\}]+)\}/&subst_strong($1)/ieg;
        $o_buffer .= ">$col";
        $o_buffer .= "</t$1>" if ($out =~ /<t(d|h)/);
    }
    $o_buffer .= "</tr>\n";
    return($o_buffer);
}
sub make_helper_script {
    my (@help_text) = @_;
    my ($script, $i);
    $script .= qq/var HelpText=new Array($#{help_text});\n/;
    $i = 0;
    foreach (@help_text) {
        $script .= qq/HelpText[/ . $i++ . qq/] = "$_";\n/;
    }
    $script .=<<'EOB';
function HelpWin(num){var win=window.open("","_blank",
"toolbar=0,location=0,directories=0,status=0,menubar=0,"+
"scrollbars=0,resizable=1,width=200,height=250");with(win.document){
open();writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">');
writeln("<html><head><title>設定追加情報<","/title>");
writeln("<style type='text/css'><!--body{font-family:sans-serif;}");
writeln("--><","/style><","/he","ad><bo","dy>",HelpText[num],"<br>");
writeln("<div align=right><form>");
writeln("<input type='button' value='閉じる' onClick='window.close()'>");
writeln("<","/form><","/div><","/body><","/html>");close();}}
EOB
    return ($script);
}

sub make_layer_script {
    my ($script);
    $script .=<<"EOB";
function showLayer(n){var d=document;if(d.all)y=d.all.tags('span');
if(d.layers)y=d.layers['lay1'].document.layers;for(i=0;y&&i<y.length;i++){
var l=y[i];var m=l.id;if(l.style){l=l.style;s='';h='none';if(m==n)l.display=s;
else l.display=h;}else{s='show';h='hide';if(m==n)l.visibility=s;else
l.visibility=h;}}if(d.all&&d.all.tags('td')){y=d.all.tags('td');
for(i=0;i<y.length;i++){if(y[i].id.indexOf("tabobj")==0){if(y[i].id=='tab'+n)
{y[i].className='seltab';}else{y[i].className='tab';}}}}}function setVals(){
var d=document;f=d.forms['formSend'];if(!(d.layers))return;
d=d.layers['lay1'].document;for(i=0;d.layers&&i<d.layers.length;i++){
l=d.layers[i].document.forms[0];for(j=0;l.elements&&j<l.elements.length;j++){
e=l.elements[j];if(e.type=="radio"&&!e.checked)continue;if(f.elements[e.name])
f.elements[e.name].value=e.value;}}}
EOB
    return ($script);
}

sub make_style {
  my ($chcv, $style);
  ($chcv = $caption_head_color) =~ s/ bgcolor="?([^"]+)"?/$1/;
  $style =<<"EOS";
<style type="text/css"><!--
.tab{background:$body{'bgcolor'} no-repeat left top;border:#666666 1pt solid;
color:$body{'text'};cursor:hand;font-family:<%=gloc_FontName%>;font-size:8pt;
font-weight:normal;padding-top:3px;text-decoration:none;}.seltab{
background:$chcv no-repeat left top;border-top:#666666 1pt solid;
border-left:#666666 1pt solid;border-right:#666666 1pt solid;
color:black;cursor:hand;font-family:<%=gloc_FontName%>;font-size:8pt;
font-weight:bold;padding-top:3px;text-decoration:none;}.hiddentab{
background:$body{'bgcolor'};border-bottom:#666666 1pt solid;
color:$body{'bgcolor'};}.tabbody{border-left:#666666 1pt solid;
border-bottom:#666666 1pt solid;border-right:#666666 1pt solid;
padding:5px;}.tabs{border-bottom:#666666 1px solid;margin:-1px;}.tabbtn1{
background:#6699cc;color:white;cursor:hand;font-family:<%=gloc_FontName%>;
font-size:9pt;font-weight:normal;text-decoration:none;}.tabbtn2{
background:#999999;color:white;cursor:hand;font-family:<%=gloc_FontName%>;
font-size:x-small;font-weight:normal;text-decoration:none;}.hint{
position:absolute;padding:0 2 0 2;font-size:x-small;color:black;width:200px;
border:black 1px solid;background-color:#FFFFDD;layer-background-color:#FFFFDD;
visibility:hidden;z-index:0;}
--></style>
EOS
    $extra_header .= $style;
}

sub make_switch_dhtml {
    my ($d) = ($FORM{'disable_dhtml'})?
        "" : '<input type="hidden" name="disable_dhtml" value="true">';
    my ($m) = ($FORM{'disable_dhtml'})? '有効' : '無効';
    my ($s) = ($FORM{'disable_dhtml'})? '' : ' class=tabbtn1';
    $buffer .=<<"EOB";
<div align=right><form method="POST" action="$bbs_local">
<input type="hidden" name="a" value="ch_init">
<input type="hidden" name="authorize" value="$COOKIE{'authorize'}">
$d<input type="submit" value="DHTML$m"$s></form></div>
EOB
}

sub make_hint_script {
    $extra_header .=<<'EOS';
<script type="text/javascript" language="JavaScript1.2"><!--
var cw=200;var ch=0;var ver4=(parseInt(navigator.appVersion)>=4);
function doHint(x,y,id){if(ver4){var d=document;if(d.all)d=d.all;
var h=d[id];if(h.style)h=h.style;var dw=0;if(document.body){
db=document.body;dw=db.clientWidth;if(db.scrollTop)y=y+db.scrollTop;
if(db.scrollLeft)x=x+db.scrollLeft;}if(!dw)dw=window.innerWidth;
var r=x+cw;h.left=(r<dw)?x:(dw-cw);h.top=y+20;var t=(h.clip)?h.clip:h;
if(ch>0)t.height=ch;if(cw>0)t.width=cw;h.visibility="visible";}}
function stopHint(id){if(ver4){var d=document;if(d.all)d=d.all;
var h=d[id];if(h.style)h=h.style;h.visibility="hidden";}}//--></script>
EOS
}

1;
