<?
  // echo "funs.php 成功載入<BR>";
  require_once ("./etc/init.php");
	
  class W_user
  {
    var $operator = "";		// 信件類別 identification、new_password)
    var $user = "";		// 使用者帳號
    var $email = "";		// 使用者註冊 e-mail
    var $new_password = "";	// 新密碼
    var $activate_code = "";	// 認證碼
    var $hadoop_user = "";	// hadoop 帳號
    var $hadoop_password = "";	// hadoop 密碼

    // 重新導向
    function redirect_to($w_url, $message)
    {
      header ("refresh:5 ;url=$w_url");
      echo "<BR> 此網頁將於 5 秒後重新導向 <BR>";
      echo "<BR> ======== System Message ========";
      echo "<BR>" . $message;
    }

    // 取得認證信內容
    function get_activate_mailbody()
    {
      global $w_localhost;	// 載入主機位址環境變數
      $str = '
	      <br>
	      <br>您好：
	      <br>
	      <br>請點選以下認證碼啟動您的 Hadoop 帳號：
	      <br>
	      <br>
	      ';
      $str .= "<br><A href=http://" . "$w_localhost" . "check_activate_code.php?user=" .
      $this->user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號</A>";
      return $str;
    }

    // 取得密碼信內容
    function get_new_password_mailbody()
    {
      global $w_localhost;        // 載入主機位址環境變數
      $str = '
              <br>
              <br>您好：
              <br>
              <br>以下為您新的密碼：
              <br>
              <br>
              ';
      $str .= "
	      <br>請使用以下設定
	      <br>帳號：$this->user
	      <br>密碼：$this->new_password
	      <br>登入 http://$w_localhost。
	      ";
      return $str;
    }

    // 取得 hadoop 帳號密碼信內容
    function get_hadoop_user_password_mailbody()
    {
      global $w_localhost;        // 載入主機位址環境變數
      $str = '
              <br>
              <br>您好：
              <br>
              <br>以下為您所申請的 Hadoop 帳號及密碼：
              <br>
              <br>
              ';
      $str .= "
	      <br>位址：$w_localhost
              <br>帳號：$this->hadoop_user
              <br>密碼：$this->hadoop_password
	      <br>
	      <br>請用<a href=\"http://www.csie.ntu.edu.tw/~piaip/pietty/\">SSH Client</a>登入使用。
	      <br>Ex. ssh $w_localhost -l $this->hadoop_user
                ";
            return $str;
    }

    // 取得認證碼
    function get_activate_code()
    {
      return md5($this->user . microtime() );	
    }

    // 取得新密碼
    function get_new_password()
    {
			return rand();
		}

		function test()
		{
			echo "<br>========";
			echo "<br>this is in W_user->test() <br>";
            $str = "<br><A href=http://" . "$w_localhost" . "check_activate_code.php?user=" .
        		   $this->user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號</A>";
			//echo $this->user;
			//echo $this->activate_code;
		}
	}
?>
