<?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 registration 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 `registration` (salutation, name, surname, feetype, email, phone, position, depfak, organization, postal, city, stateprov, zipcode, country, presentationtype, additional, date_registered, time_reg, regcode, activation) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
					   
					   GetSQLValueString($_POST['salutation'], "text"),
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['surname'], "text"),
                       GetSQLValueString($_POST['feetype'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['position'], "text"),
                       GetSQLValueString($_POST['depfak'], "text"),
                       GetSQLValueString($_POST['organization'], "text"),
                       GetSQLValueString($_POST['postal'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['stateprov'], "text"),
                       GetSQLValueString($_POST['zipcode'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                       GetSQLValueString($_POST['presentationtype'], "text"),
                       GetSQLValueString($_POST['additional'], "text"),
                       GetSQLValueString($_POST['date_registered'], "text"),
                       GetSQLValueString($_POST['time_registered'], "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_ok.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>Registration Form</h1>
    <p>INTERNATIONAL CONFERENCE ON Integrated Coastal Management and Marine Biotechnology already held on November 2016. <br />
    For further information, please email  to our Conference Secretariat ( <span class="style1">icmbt2016@pksplipb.or.id</span> ).</p>
    <p>Thank You. <br />
    </p>
    <h3>
      <input type="hidden" name="activation" />
      <input type="hidden" name="MM_insert" value="form1" />
    </h3>
    
    <h3>
      <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>
