<?
if(!(isset($_SESSION))){session_start();}
/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact-dist.php 133 2008-05-23 16:08:06Z emartin24 $
 *
 */
/*
// User settings
$to = 'user@yourdomain.com';
$subject = 'SimpleModal Contact Form';

// Include extra submitter data?
// FALSE = do not include
$extra = array(
	'ip'		 => TRUE,
	'user_agent' => TRUE
);
*/
// Process
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
if (empty($action)) 
{
	// Send back the contact form HTML

?> 

    <div style='display:none'>
	<a href='#' title='Close' class='modalCloseX modalClose'>x</a>
	<div class='contact-top'></div>
	<div class='contact-content'>
		<h1 class='contact-title'>歡迎加入揪咪揪團網:</h1>
		<div class='contact-loading' style='display:none'></div>
		<div class='contact-message' style='display:none'></div>
		<br>
		<form action='#' style='display:none' id="mr" name="mr" enctype="multipart/form-data" >
			<label for='mAccount'>*帳號:</label>
			<input type='text' id='contact-mAccount' class='contact-input' name='mAccount'  size="20" maxlength="15" 
			onkeyup="checkUsername(event,'showDiv');"/>
			<span id="showDiv" maxlength='5'></span><br>
			<label for='password'>*密碼:</label>
			<input type='password' id='contact-password' class='contact-input' name='password'  size="25" maxlength="20"/>
			(建議20字數以內)<br/>
			<label for='password'>*確認密碼:</label>
			<input type='password' id='contact-password1' class='contact-input' name='password1'  size="25" maxlength="20"/><br/>
			<label for='name'>*姓名:</label>
			<input type='text' id='contact-name' class='contact-input' name='mName'  size="10" maxlength="8" /><br/>
			<label for='nickname'>*暱稱:</label>
			<input type='text' id='contact-nickname' class='contact-input' name='nickname' size="20" maxlength="15" />(建議15字數以內)	
			<br/>
			<label for='sex'>*性別:</label>
			<input type='radio' id='contact-sex'  name='sex'  value =1>女
			<input type='radio' id='contact-sex'  name='sex'  value =2>男
			<br/>
			<label for='birthday'>*生日:</label>
     			<select id='contact-birthday_y' name='birthday_y' class='contact-input1' > 
            <option value=""></option>
			<?
			for ($i = 1950; $i <=date(Y); $i++){ ?>
			  	<option value="<?=$i?>"><?=$i?></option>
			<?
			}
			?>
			</select>
     		年
			<select id='contact-birthday_m' name='birthday_m' class='contact-input1' > 
            <option value=""></option>
			<?
			for ($i = 1; $i <=12; $i++){ ?>
			  	<option value="<?=$i?>"><?=$i?></option>
			<?
			}
			?>
			</select>月 
			<select id='contact-birthday_d' name='birthday_d' class='contact-input1'> 
            <option value=""></option>
			<?
			for ($i = 1; $i <=31; $i++){ ?>
			  	<option value="<?=$i?>"><?=$i?></option>
			<?
			}
			?>
			</select>日 
			<label for='mEmail'>*電子信箱:</label>
			
			<input type='text' id='contact-mEmail' class='contact-input' name='mEmail' size="40" maxlength="40"/><br>
			<label>&nbsp;</label>
			<font color="#FF0000" >若忘記密碼，將會寄到此E-mail!!!</font><br>
			<label for='mMsn'>*即時通訊:</label>
			<input type='text' id='contact-mMsn' class='contact-input' name='mMsn'  size="40" maxlength="40"/>
			<br/>
			
			<label for='mPic'>個人圖像:</label>
			<input id="fileToUpload" class='contact-input' type="file"  name="fileToUpload" class="input">
			<!--<input type='file' id='contact-mPic' class='contact-input' size="45" name='mpic' />-->
			<br/>
			<label>&nbsp;</label>
			<button type='submit' class='contact-send contact-button' >Send</button>
			<button type='submit' class='contact-cancel contact-button modalClose' >Cancel</button>
			<label for='mEmail'><input type='checkbox' id='chkrule' name='chkrule' onclick="rule();">服務條款:</label><br>
			<label for='rule' style="text-align:left;">&nbsp;</label>
				<div id="rule" style="display:none;overflow:scroll; width:450px; height:80px; margin: 0px auto;"><pre>
1. 認知與接受條款 
   JUME係依據本服務條款提供JUME服務以下簡稱"本服務"
   。當您使用本服務時，即表示您已閱讀、瞭解並同意
   接受本服務條款之所有內容。JUME有權於任何時間修改
   或變更本服務條款之內容，建議您隨時注意。
2. 與第三人網站的連結 
   連結至其他業者經營的網站，但不表示JUME與該業者有
   任何關係。其他業者經營的網站均由各該業者自行負責，
   不屬JUME控制及負責範圍。
3. 您的註冊義務
   提供您本人正確、最新及完整的資料，維持並更新您
   個人資料，確保其為正確。若您提供任何錯誤、不實或
   不完整的資料，JUME有權暫停或終止您的帳號，並拒絕
   您使用本服務之全部或一部。
4. 使用者的守法義務及承諾 
   您承諾絕不為任何非法目的或非法方式使用本服務，
   並承諾遵守中華民國相關法規及網際網路之國際慣例。
5. 會員行為 
   由會員公開張貼或私下傳送的資訊、資料、文字、軟體、
   音樂、音訊、照片、圖形、視訊、信息或其他資料以下
   簡稱「會員內容」，均由「會員內容」提供者自負責任。
6. 您對JUME之授權 
   若您無合法權利授權他人使用、修改、重製、
   公開播送、改作、散布、公開發表某資料，並將前述
   權利轉授權第三人，請勿擅自將該資料上載、傳送、
   輸入或提供予JUME您所上載、傳送、輸入或提供予JUME
   之任何資料，其權利仍為您的授權人所有
7. 拒絕或終止您的使用 
   您同意JUME得基於其自行之考量，因任何理由，而終止
   您的密碼、帳號（或其任何部分）或本服務之使用，並
   將本服務內任何「會員內容」加以移除並刪除。
</pre>
			</div>
				
			
			
			<br/>
		<label>&nbsp;</label>
			
			
		</form>
	</div>
	<div class='contact-bottom'></div>
</div>

<?
}
else if ($action == 'send') {
require_once("../db.php");
	// send data
	$mAccount = isset($_REQUEST['mAccount']) ? $_REQUEST['mAccount'] : '';
	$password = md5(isset($_REQUEST['password']) ? $_REQUEST['password'] : '');
	$password1 = isset($_REQUEST['password1']) ? $_REQUEST['password1'] : '';	
	$mName = isset($_REQUEST['mName']) ? $_REQUEST['mName'] : '';
	$nickname = isset($_REQUEST['nickname']) ? $_REQUEST['nickname'] : '';
	$sex = isset($_REQUEST['sex']) ? $_REQUEST['sex'] : '';
	$birthday_y = isset($_REQUEST['birthday_y']) ? $_REQUEST['birthday_y'] : '';
	$birthday_m = isset($_REQUEST['birthday_m']) ? $_REQUEST['birthday_m'] : '';
	$birthday_d = isset($_REQUEST['birthday_d']) ? $_REQUEST['birthday_d'] : '';
	$mEmail = isset($_REQUEST['mEmail']) ? $_REQUEST['mEmail'] : '';
	$mMsn = isset($_REQUEST['mMsn']) ? $_REQUEST['mMsn'] : '';
$ip=$_SERVER['REMOTE_ADDR'];

	$mAccount=nl2br(htmlspecialchars($mAccount));
$password=nl2br(htmlspecialchars($password));
$mName=nl2br(htmlspecialchars($mName));
$nickname=nl2br(htmlspecialchars($nickname));
$sex=nl2br(htmlspecialchars($sex));
$birthday_y=nl2br(htmlspecialchars($birthday_y));
$birthday_m=nl2br(htmlspecialchars($birthday_m));
$birthday_d=nl2br(htmlspecialchars($birthday_d));
$mEmail=nl2br(htmlspecialchars($mEmail));
$mMsn=nl2br(htmlspecialchars($mMsn));


  $str="INSERT INTO member (mAccount,password,mName,nickname,sex,birthday_y,birthday_m,birthday_d,mEmail,mMsn,mIp,oPa) VALUES 
      ('$mAccount','$password','$mName','$nickname','$sex','$birthday_y','$birthday_m','$birthday_d','$mEmail','$mMsn','$ip','$password1')";
	
  mysql_query($str);
  /*
  $error = "";
	$msg = "";
	$fileElementName = 'fileToUpload';
	if(!empty($_FILES[$fileElementName]['error']))
	{
		switch($_FILES[$fileElementName]['error'])
		{

			case '1':
				$error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
				break;
			case '2':
				$error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
				break;
			case '3':
				$error = 'The uploaded file was only partially uploaded';
				break;
			case '4':
				$error = 'No file was uploaded.';
				break;

			case '6':
				$error = 'Missing a temporary folder';
				break;
			case '7':
				$error = 'Failed to write file to disk';
				break;
			case '8':
				$error = 'File upload stopped by extension';
				break;
			case '999':
			default:
				$error = 'No error code avaiable';
		}
	}else if(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')
	{
		//$error = 'No file was uploaded..';
	}else 
	{
			/*
			$msg .= " File Name: " . $_FILES['fileToUpload']['name'] . ", ";
			$msg .= " File Size: " . @filesize($_FILES['fileToUpload']['tmp_name']);
			//for security reason, we force to remove all uploaded file
			@unlink($_FILES['fileToUpload']);		
			$dir="mpic/";
			$query_news_id = "SELECT MAX(mId) FROM member";
	$Result_news = mysql_query($query_news_id);
	$mId = mysql_fetch_array($Result_news);
			$pName = $_FILES['fileToUpload']['name'];
		$tmpname = $_FILES['fileToUpload']['tmp_name'];
		$subname = explode(".",$pName);
		$pName = $dir.$mId[0].".".$subname[1];
		$mod_doc = "update member set mPath = '$pName' where mId = '$mId[0]'";
		$result_mod_doc = mysql_query($mod_doc);
		if (copy($tmpname,$pName))
		{
			unlink($tmpname);
		}
			
			
	}	
	
	echo "{";
	echo				"error: '" . $error . "',\n";
	echo				"msg: '" . $msg . "'\n";
	echo "}";
	*/
  echo "恭喜!您已註冊成功";
  
}
/*
// Validate and send email
function sendEmail($name, $email, $message) {
	global $to, $subject, $extra;

	// Filter name
	$name = filter($name);

	// Filter and validate email
	$email = filter($email);
	if (!validateEmail($email)) {
		$subject .= " - invalid email";
		$message .= "\n\nBad email: $email";
		$email = $to;
	}

	// Add additional info to the message
	if ($extra['ip']) {
		$message .= "\n\nIP: " . $_SERVER['REMOTE_ADDR'];
	}
	if ($extra['user_agent']) {
		$message .= "\n\nUSER AGENT: " . $_SERVER['HTTP_USER_AGENT'];
	}

	// Set and wordwrap message body
	$body = "From: $name\n\n";
	$body .= "Message: $message";
	$body = wordwrap($body, 70);

	// Build header
	$header = "From: $email\n";
	$header .= "X-Mailer: PHP/SimpleModalContactForm";

	// Send email
	@mail($to, $subject, $body, $header) or 
		die('Unfortunately, your message could not be delivered.');
}

// Remove any un-safe values to prevent email injection
function filter($value) {
	$pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i");
	$value = preg_replace($pattern, '', $value);
	return $value;
}

// Validate email address format in case client-side validation "fails"
// Validate email address format in case client-side validation "fails"
function validateEmail($email) {
	$at = strrpos($email, "@");

	// Make sure the at (@) sybmol exists and  
	// it is not the first or last character
	if ($at && ($at < 1 || ($at + 1) == strlen($email)))
		return false;

	// Make sure there aren't multiple periods together
	if (preg_match('/(\.{2,})/', $email))
		return false;

	// Break up the local and domain portions
	$local = substr($email, 0, $at);
	$domain = substr($email, $at + 1);


	// Check lengths
	$locLen = strlen($local);
	$domLen = strlen($domain);
	if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255)
		return false;

	// Make sure local and domain don't start with or end with a period
	if (preg_match('/(^\.|\.$)/', $local) || preg_match('/(^\.|\.$)/', $domain))
		return false;

	// Check for quoted-string addresses
	// Since almost anything is allowed in a quoted-string address,
	// we're just going to let them go through
	if (!preg_match('/^"(.+)"$/', $local)) {
		// It's a dot-string address...check for valid characters
		if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local))
			return false;
	}

	// Make sure domain contains only valid characters and at least one period
	if (!preg_match('/^[-a-zA-Z0-9\.]*$/', $domain) || !strpos($domain, "."))
		return false;	

	return true;
}

exit;
*/
?>