#!/usr/bin/perl

use CGI qw(:standard);

use Convert::UU;
use Convert::UUlib;
use Convert::BinHex;
use HTML::Escape qw(escape_html);
use MIME::Base64;
use MIME::QuotedPrint;
use URI::Escape qw(uri_escape);

print header(-charset=>'utf-8');
print start_html(-bgcolor=>'#F8F4E7', -title=>'編碼教具');

print '<H1 ALIGN="center">編碼教具</H1>';

if (param('tf')) {
	$tf = param('tf');
	print "<H2 ALIGN=\"center\">原文：", escape_html($tf), "</H2>\n";
	print "<BLOCKQUOTE><DL>\n";

	print "<DT><B>Base64</B><BR />\n";
	print "<DD>", encode_base64($tf), "<BR />\n";

	print "<DT><B>Quoted Printable</B><BR />\n";
	print "<DD>", escape_html(MIME::QuotedPrint::encode($tf)), "<BR />\n";

	print "<DT><B>URL</B><BR />\n";
	print "<DD>", uri_escape($tf), "<BR />\n";

	print "<DT><B>UU encode</B><BR />\n";
	print "<DD>";

	@uuoutput = split("\n", Convert::UU::uuencode($tf));
	foreach(@uuoutput) {
		if($_ !~ 'begin' && $_ !~ 'end') {
			print escape_html($_);
		}
	}

	print "<BR />\n";

	my $b2h = Convert::BinHex->bin2hex;
	print "<DT><B>BinHex</B><BR />\n";
	print "<DD>", escape_html($b2h->next($tf)), escape_html($b2h->done), "<BR />\n";

	print "</DL></BLOCKQUOTE>\n";
	print hr, "\n";
}

print '您可以在下面的欄位中輸入最多 24 拜的文字，以進行編碼示範：', br, br, "\n";

print start_form(), "\n";
#print "輸入字串：", textfield(-name=>'tf', -maxlength=>'24'), "\n";
print "輸入字串：<input type=\"text\" name=\"tf\" maxlength=\"24\">\n";
print submit(-value=>'編碼'), "\n";
print " &nbsp; <INPUT TYPE=\"button\" VALUE=\"關閉\" onClick=\"window.close();\">\n";
print end_form, "\n";

print << 'END';

<!-- Light Panel for Deep Pages -->

<P><HR WIDTH=10% NOSHADE COLOR=#00BB00 ALIGN=left>
<TABLE ALIGN=center WIDTH=80% BORDER=0>
<TR><TD WIDTH=25% VALIGN=top><B>製作人、<BR>修改記錄</B></TD>
<TD WIDTH=75% VALIGN=top>
周恩冉 (2002/11/13) -- 08/12/20 (歐), 15/11/01 (單), 17/03/09 (偉)

END

print end_html();
