<?php
//
// BBWA
// functions.php
// いろいろな関数
// Teppei KAKU <teppei@sat.co.jp>
//

// エラーや投稿・削除後のメッセージを表示
function printHtml($message, $right, $left) {
  include("variables.php");

  echo <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
<meta http-equiv="Refresh" content="2;URL=${right}">
<link rel="stylesheet" type="text/css" href="Themes/${theme}.css">
<script language="JavaScript">
<!--
function updateLeft(submitType) {
  order = parent.TOP.document.sf.ss.selectedIndex;
  switch (submitType) {
    case "NEW":
      if (order == 2) {
        parent.LEFT.location.href="left.php?page=END&order=2";
      } else {
        parent.LEFT.location.href="left.php?page=1&order=" + order;
      }
      break;
    case "COM":
      if (order == 0) {
        parent.LEFT.location.href="left.php?page=1&order=0";
      }
      break;
    case "DEL":
      parent.LEFT.location.reload();
      break;
    case "SCO":
      if (order == 3) {
        parent.LEFT.location.reload();
      }
      break;
  }
}
//-->
</script>
</head>
EOD;

  if ($left != "") {
    print("<body class=\"right\"" .
      "onLoad=\"updateLeft('${left}')\">");
  } else {
    print("<body class=\"right\">");
  }

  echo <<<EOD
<strong>
${message}<br>
<a href="${right}">
しばらくお待ちください・・・</a><br>
</strong>
</body></html>
EOD;

  exit();
}

// タグ変換・リンク張りを行う
function messageParse($message) {
  $message = stripslashes($message);
  $message = ereg_replace(
    "(http|https|ftp|mailto):[a-zA-Z0-9/%&=_:+~@\-\?\.]*",
    "<a href=\"\\0\" target=\"_blank\">\\0</a>", $message);
  $message = ereg_replace("{{BR}}", "<br>", $message);
  $message = ereg_replace("{{LT}}", "&lt;", $message);
  $message = ereg_replace("{{GT}}", "&gt;", $message);

  return $message;
}

// タグ変換を行う
function messageParse2($message) {
  $message = stripslashes($message);
  $message = ereg_replace("(\r|\n|\r\n)$", "", $message);
  $message = ereg_replace("{{BR}}", "\n", $message);
  $message = ereg_replace("{{LT}}", "&lt;", $message);
  $message = ereg_replace("{{GT}}", "&gt;", $message);

  return $message;
}
?>
