<?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 and sesi=2", 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;
}
}

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

$sesi = 2;
$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` (sesi, 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, %s)",
					   
					   GetSQLValueString($_POST['sesi'], "text"),
					   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>
   The 2<sup>nd</sup> International Conference on Integrated Coastal Management and Marine Biotechnology<br />
    Please email your abstract to our Conference Secretariat ( <span class="style1">icmmbt@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>The 2<sup>nd</sup> International Conference on Integrated Coastal Management and Marine Biotechnology 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">* Salutation:</td>
            <td width="65%">
              <input  name='salutation' type='radio' value="Mr." checked="checked" />
              Mr. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type='radio' value="Ms."  name='salutation' />Ms. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type='radio' value="Mrs."  name='salutation' />Mrs. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type='radio' value="Prof."  name='salutation' />Prof. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type='radio' value="Dr."  name='salutation' />Dr.            </td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* First Name:</td>
            <td><input type="text" name="name" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Surname:</td>
            <td><input name="surname" type="text" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Fee Type:</td>
            <td>
            	<input  name='feetype' type='radio' value="Full" checked="checked" />
           	  Full (IDR) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           	<input type='radio' value="Student"  name='feetype' />Student (IDR)</td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Email:</td>
            <td><input type="text" name="email" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Phone :</td>
            <td><input name="phone" type="text" value="" size="15" maxlength="15" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Position Held :</td>
            <td><input type="text" name="position" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Departement/Faculty :</td>
            <td><input type="text" name="depfak" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Organization :</td>
            <td><input type="text" name="organization" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td align="right" valign="middle" nowrap="nowrap">* Postal Address :</td>
            <td><textarea name="postal" cols="38" required></textarea></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* City :</td>
            <td><input type="text" name="city" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* State/Province :</td>
            <td><input type="text" name="stateprov" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Zip Code :</td>
            <td><input name="zipcode" type="text" value="" size="8" maxlength="5" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Country :</td>
            <td><input type="text" name="country" value="" size="50" required/></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">* Presentation Type  :</td>
            <td><b>
              <select name="presentationtype" required>
               <option value='I Will Not Present'>I Will Not Present</option>
               <option value='Oral'>Oral</option>
                <option value='Poster'>Poster</option>
              </select>
            </b></td>
          </tr>
          <tr valign="baseline">
            <td align="right" valign="middle" nowrap="nowrap">Additonal Information / <br>Instructions :</td>
            <td><textarea name="additional" cols="38">-</textarea></td>
          </tr>

          <tr valign="baseline">
            <td nowrap="nowrap" align="right"><input type="hidden" name="sesi" value="<?php echo $sesi; ?>" size="10" />
              <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:icmmbt@pksplipb.or.id">Contact Us</a> | <a href="admin/">Admin</a> | </div>
</div>
</body>
</html>
