<?php require_once('connections/reg_conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect= "register_error.php";

//$MM_dupKeyRedirect="register_error.php";
$res_email = $_POST['email'];
$emailCek__query = sprintf("SELECT email FROM kp_questioner WHERE email=%s", GetSQLValueString($res_email, "text"));
mysql_select_db($database_reg_conn, $reg_conn);
$emailCek=mysql_query($emailCek__query, $reg_conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($emailCek);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
header ("Location: $MM_dupKeyRedirect");

exit;
}
}

//############################################################################################################//

$date_registered = date("Y-m-d");
$time_registered = gmdate("H:i:s", time()+60*60*7);
		
  function regcode($n = 6) {
     $akod = NULL;
     $kode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 
  for ($i=0; $i<$n; $i++) {
     $acakangka = rand(1, strlen($kode));
     $akod .= substr($kode, $acakangka, 1);
  }
  return $akod;
  }			
  
//############################################################################################################//

		

			

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	$my_activation= md5($_POST['regcode']); 
  $insertSQL = sprintf("INSERT INTO `kp_questioner` (email, regcode, activation) VALUES (%s, %s, %s)",
					   
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['regcode'], "text"),
                       GetSQLValueString($my_activation, "text"));

  mysql_select_db($database_reg_conn, $reg_conn);
  $Result1 = mysql_query($insertSQL, $reg_conn) or die(mysql_error());

  $insertGoTo = "register_oke.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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=utf-8" />
<title>Registration Page</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #0000FF}
-->
</style>
</head>

<body>

<div class="container">
  <div class="header"></div>
  <div class="content">
    <h1>Kirim Questioner </h1>
    INTERNATIONAL CONFERENCE ON Integrated Coastal Management and Marine Biotechnology<br />
    Please email your abstract to our Conference Secretariat ( <span class="style1">icmbt2016@pksplipb.or.id</span> ) quoting your 6-digit registration in the email subject.<br />
    <h3><em>Fields marked with ( * ) must be filled.</em></h3>
    
    <h2>Registration Detail</h2>
    <h3>
      <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        <table align="center">
          <tr valign="baseline">
            <td width="35%" align="right" nowrap="nowrap">* Email:</td>
            <td width="65%"><input type="text" name="email" value="" size="50" required/></td>
          </tr>

          <tr valign="baseline">
            <td nowrap="nowrap" align="right"><input type="hidden" name="regcode" value="<?php  echo regcode($n = 6); ?>" size="10" />
            <input type="hidden" name="date_registered" value="<?php echo $date_registered; ?>" size="10"  />
            <input type="hidden" name="time_registered" value="<?php echo $time_registered; ?>" size="10" /></td>
            <td><input type="submit" value="Submit" /></td>
          </tr>
        </table>
        <input type="hidden" name="activation" />
        <input type="hidden" name="MM_insert" value="form1" />
      </form>
      <p>&nbsp;</p>
    </h3>
</div>
  <div class="nelayan"></div>
  <div class="footer"><a href="http://pksplipb.or.id/int/icmmbt/"><br />
    | Home</a> | <a href="http://pkspl.ipb.ac.id">About</a> | <a href="mailto:icmbt2016@pksplipb.or.id">Contact Us</a> | <a href="admin/">Admin</a> | </div>
</div>
</body>
</html>
