// echo "funs.php 成功載入
";
   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 '';
         echo "
 此網頁將於 5 秒後重新導向 
";
	 echo "
 ======== System Message ========";
	 echo "
" . $message;
      }
      // 取得認證信內容
      function get_activate_mailbody()
      {
	 global $w_localhost;	// 載入主機位址環境變數
	 $str = '
		  
		  
您好:
		  
		  
請點選以下認證碼啟動您的 Hadoop 帳號:
		  
		  
		  ';
	 $str .= "
user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號";
	 return $str;
      }
      // 取得密碼信內容
      function get_new_password_mailbody()
      {
	 global $w_localhost;        // 載入主機位址環境變數
	 $str = '
		  
		  
您好:
		  
		  
以下為您新的密碼:
		  
		  
		  ';
	 $str .= "
		  
請使用以下設定
		  
帳號:$this->user
		  
密碼:$this->new_password
		  
登入:$w_localhost
		  ";
	 return $str;
      }
      // 取得 hadoop 帳號密碼信內容
      function get_hadoop_user_password_mailbody()
      {
	 global $w_localhost;       // 載入主機位址環境變數
	 global $w_ssh_server;	    // 載入 ssh 主機位址
	 $str = '
		  
		  
您好:
		  
		  
以下為您所申請的 Hadoop 帳號及密碼:
		  
		  
		  ';
	 $str .= "
		  
位址:$w_localhost
		  
帳號:$this->hadoop_user
		  
密碼:$this->hadoop_password
		  
		  
請用SSH Client登入使用。
		  
Ex. ssh $w_ssh_server -l $this->hadoop_user
		  ";
	 return $str;
      }
      // 取得認證碼
      function get_activate_code()
      {
	 return md5($this->user . microtime() );	
      }
      // 取得新密碼
      function get_new_password()
      {
	 return rand();
      }
   }
   class W_mysql
   {
      function connect()
      {
	 require ("init.php");
	 // 連結資料庫
	 $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error());
	 mysql_select_db($mysql_database, $link) or die(mysql_error() );
	 mysql_query("SET NAMES 'utf8'");
	 return $link;
      }
      function count_is_active_user($link)
      {
	 require ("init.php");
	 $str = sprintf("SELECT COUNT(*)
			 FROM `%s` 
			 WHERE `is_activate` = 1
			 GROUP BY `is_activate`
			",$mysql_table);
	 $result = mysql_query($str , $link) or die(mysql_error() );
	 $row = mysql_fetch_row($result);
	 return $row[0]; 
      }
      function close($link)
      {
	 mysql_close($link);
      }
   }
   function test()
   {
      echo "
========";
      echo "
this is in W_user->test() 
";
      $str = "
user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號";
      //echo $this->user;
      //echo $this->activate_code;
   }
?>