#!%PERL_PATH%

# HyperNikkiSystem RuriMap Maker
# version 0.0.4
# 2000/9/26  TANAKA Tomonari <tom@morito.mgmt.waseda.ac.jp>
# this code is based on php version.

my $version = "0.0.4";

# Copyright (C) 1999,2000 TANAKA Tomonari, HyperNikkiSystem Project

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

# $Id: make-rurimap.cgi.in,v 1.10 2000/09/26 09:35:34 kenji Exp $

use strict;
use lib qw(lib);

use SimpleDB::Scalar;
use SimpleDB::Hash;
use SimpleDB::Append;
use CGI::QueryString;
use CGI::Cookie;
use CGI::Tools;
use HNS::System;
use HNS::Status;
use HNS::Admini;

require 'jcode.pl';
require './config.ph';

my $admini = new HNS::Admini;

################################################################
# form values
my ($name, $mail, $email, $url, $msg) =
    (param('NAME'), param('MAIL'), param('EMAIL'), param('URL'), 
    param('MSG'));

#kanji convert and escape
for ($name, $msg){
    &jcode::convert(*_, 'euc');
}
$msg =~ s/\r\n/\n/g;

# if name is set, record to ruri_map
if ($name){
    my $file = sprintf("%s", $admini->ruri_map_file);
    my $ruri_map_file = new SimpleDB::Append("$file");
    my $id = sprintf("%s", $admini->status->id);
    $ruri_map_file->Append("$id $name\n");
}

# if any message is written, record it to user_message.txt
if ($msg || $email || $url){
    my $user_msgs;
    tie $user_msgs, 'SimpleDB::Scalar', $admini->message_file;
    $user_msgs .= sprintf("%s\n%s %s %s\n%s\n%s\n%s\n-----\n",
			  $admini->status->date_time,
			  $admini->status->id, $admini->status->count, $name,
			  $email, $url,
			  $msg);
#    print "content-type: text/plain\n\n";
#    print "data:$user_msgs";
}

# if you have any message, send a mail.
if ($msg && $HNS::System::MesMail) {
	my $tomail;
	for ($name, $msg){
		&jcode::convert(*_, 'jis');
	}
	$email = $HNS::System::UserMail unless $email;
	$tomail = $HNS::System::MesMail;
	open(MAIL, "| %SENDMAIL_PATH% -t -f'$tomail'");
	print(MAIL "From: <$email>\r\n");
	print(MAIL "To: $tomail\r\n");
	print(MAIL "Subject: [hns] Message to Diary\r\n\r\n");
	print(MAIL "Message from $name\r\n\r\n");
	print(MAIL "$msg");
	close(MAIL);
}

$admini->RedirectDiary;
exit 0;
################################################################

