<?php
/*
 * Questions to SANET
 *
 * SCRIPT NAME : send_form.php
 * CREATED : Aug 26 2008
 * LAST UPDATED : Jan 12 2011 by okunuki@nagoya-u
 * LAST UPDATED : Sep 5 2010 by fujita@csis
 * COPYRIGHT : kayo okabe;
 *
 */
 
/* USER SETTING */
/*----------------------------------------------------------*/
$mail_to = "sanet.question@gmail.com";
$mail_from = "sanet.question@gmail.com";
$subject = "SANETへの質問";

/*----------------------------------------------------------*/
/* SETTING */
$self = $_SERVER['SCRIPT_NAME'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {

	$name = trim($_POST['name']);
	$mail = trim($_POST['mail']);
	$address = trim($_POST['address']);
	$affiliation = trim($_POST['affiliation']);
	$question = trim($_POST['question']);
	

	/* ERROR CHEACK */
	if (empty($name)) {
		$errorCmt1 = "お名前<br>\n";
	}
	if (empty($mail)) {
		$errorCmt2 = "Eメールアドレス<br>\n";
	}
	if (empty($address)) {
		$errorCmt3 = "お住まいの都道府県<br>\n";
	}
	if (empty($affiliation)) {
		$errorCmt4 = "所属と職種（*大学・学生/*研究所・研究員/その他など）<br>\n";
	}
	if (empty($question)) {
		$errorCmt5 = "質問内容<br>\n";
	}
	
$message = "
<SANETへの質問>
--------------------------------------------------------------
*お名前 :  $name
*Eメールアドレス : $mail
*お住まいの都道府県 : $address
*所属（大学/研究所/その他） : $affiliation
*質問内容 : $question
";

	if ($mail > "") {
		if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $mail)) {
			$errorCmt6 = "メールアドレスに誤りがあります。<br>\n";
		}
	}

	if (isset($errorCmt1) || isset($errorCmt2) || isset($errorCmt3) || isset($errorCmt4) || isset($errorCmt5) ) {
		$error = "$errorCmt1$errorCmt2$errorCmt3$errorCmt4$errorCmt5 が未入力です。";
	}

	if (isset($errorCmt13)) {
		$error = $errorCmt13;
	}

	/* エンコーディング  */
	mb_language("Japanese");
	mb_internal_encoding("EUC-JP");

	/* メール送信 */
	if (empty($error)) {

		// $send_email = mb_send_mail($mail_to, $subject, $message, $mail_from);

		$headers = "From: $mail_from\n";
		$headers .= "Mime-Version: 1.0\n";
		$headers .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
		$headers .= "Content-Transfer-Encoding: 7bit\n";

		mail($mail_to, mb_encode_mimeheader(mb_convert_encoding($subject, "JIS"), "ISO-2022-JP", "B"), mb_convert_encoding($message, "JIS"), $headers);
		
		$msg = "<P align=\"center\">送信完了しました。</P><P align=\"center\">質問をお寄せいただきありがとうございました。一週間以内にメールで解答します。</P>\n";
		message($msg, 2);
		
	} else {
		message($error, 1);
	}
}

/* message */
function message($message, $button) {

	$back = "<input type=\"button\" value=\"　戻る　\" onclick=\"history.back()\">";
	$top = "<input type=\"button\" value=\"トップページへ\" onClick=\"top.location.href='http://sanet.csis.u-tokyo.ac.jp/index.html'\">";

	$_back = ($button == 1) ? $back : $top;

	/* エラーダイアログ設定 */
	die("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\" /><title>Questions to SANET</title></head>\n<body bgcolor=\"#E6FCFF\">\n<P align=\"center\"><font color=\"red\">$message</font></P>\n
<P align=\"center\">$_back</P>\n
</body>\n</html>");

}

?>

<!-- HTML -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp" />
<title>question to SANET</title>
</head>
<body leftmargin="30" bgcolor="#E6FCFF">
<form method="post" action="<?php echo $self; ?>">
  <table  width="600" height="600" border="0" bordercolor="#E6FCFF" bgcolor="#E6FCFF">
    <tr>
      <td width="425" align="center"><h2 align="center"><font color="#FF6600">Questions to SANET</font></h2></td>
    </tr>
    <tr>
      <td width="425" align="center"><h3 align="left"><font color="#0000FF">Please enter your question.</font></h3></td>
    </tr>
    <td width="600"　height="10"></td>
    <tr>
      <td width="600">■お名前</td>
    </tr>
    <tr>
      <td width="600"><input type="text" name="name" size="50" ></td>
    </tr>
    <tr>
      <td width="600">&nbsp;</td>
    </tr>
    <tr>
      <td width="600">■Eメールアドレス</td>
    </tr>
    <tr>
      <td width="600"><input type="text" name="mail" size="50" ></td>
    </tr>
    <tr>
      <td width="600">&nbsp;</td>
    </tr>
    <tr>
      <td width="600">■お住まいの都道府県</td>
    </tr>
    <tr>
      <td width="600"><input type="text" name="address" size="50" ></td>
    </tr>
    <tr>
      <td width="600">&nbsp;</td>
    </tr>
    <tr>
      <td width="600">■所属（大学/研究所/その他）</td>
    </tr>
    <tr>
      <td width="600"><input type="text" name="affiliation" size="50" ></td>
    </tr>
    <tr>
      <td width="600">&nbsp;</td>
    </tr>
    <tr>
      <td width="600">■質問内容を入力ください。</td>
    </tr>
    <tr>
      <td width="600"><textarea name="question" rows="8" cols="50"></textarea></td>
    </tr>
    <tr>
      <td width="600">&nbsp;</td>
    </tr>
    <tr>
      <td width="600" align="left">送信します→
      <input type="submit"  value="送信"></td>
    </tr>
<!--
    <tr>
      <td width="600" align="left">リセットします→
      <input type="submit" value="リセット"></td>
    </tr>
-->
  </table>
</form>
</body>
