<?
$pre   = '../../';
include  $pre . "common.php";
$title = "2006 US GLOBEC Pan-Regional Synthesis Meeting";
$logo  = false;
$valid = true;
$t = array('m_p','t_a','t_p','w_a','w_p','th_a','th_p');

if($_POST['but'] == "Submit"){
   $data   = $_POST;
   if(empty($data['last']) && $valid){
      $indication = 'You must enter your last name';
      $valid = false;
   }
   if(empty($data['first']) && $valid){
      $indication = 'You must enter your first name';
      $valid = false;
   }
   if(empty($data['institution']) && $valid){
      $indication = 'You must enter your institution';
      $valid = false;
   }
   if(empty($data['email']) && $valid){
      $indication = 'You must enter your email address';
      $valid = false;
   }
   if($valid){
      $valid = false;
      foreach($t as $key => $value){
         if($data[$value] == "on")
            $valid = true;
      }
      if(!$valid)
         $indication='You must choose atleast one time that you will be attending';
   }
   if(empty($data['groups1']) && $valid){
      $indication = 'You must make a first choice for a working group';
      $valid = false;
   }
   if(empty($data['groups2']) && $valid){
      $indication = 'You must make a second choice for a working group';
      $valid = false;
   }
}


if($_POST['but'] == "Submit" && $valid){
   include "audit.php";
   $audit=audit();      
}

if($_POST['but'] == "Submit" && $audit && $valid){
   $times  = '';
   $groups = '';
   

   foreach($data as $key => $value){
      if($key != "but" || $key != "userdigit"){
         if(strpos($key,'_') && !empty($value)){
            $times .= $key . ';';
         }
         else if(strpos($key,'roups')){
            $groups .= $value . ';';
         }
         else{
            $$key = $value;
         }
      }
   }
   $times  = substr($times, 0, -1);
   $groups = substr($groups, 0, -1);
         
   $tbname = TABLE_WORKSHOPS;
   $query  = "INSERT INTO $tbname SET workshop='synth06',last='$last',first='$first',institution='$institution',email='$email',times='$times',groups='$groups'";
   //echo $query;
   $result = $db->sql_query($query);
   if(!$result){
      $indication = "unknown error please try again 1";
   }
   else{
      $event_id   = $db->sql_nextid($result);
      $indication = "$first $last Added Successfully!";
      $from       = "From: lagle@marine.rutgers.edu";
      $message    = 'You have successfully registered for the 2006 U.S. GLOBEC Pan-Regional Synthesis Meeting';
      $admin_mess = "$first $last from $institution has registered for the 2006 U.S. GLOBEC Pan-Regional Synthesis Meeting using the following email address: $email";
      mail($email,"Registration Confirmation",$message,$from,"-frobertson@marine.rutgers.edu");
      mail(ADMINS,"New Register",$admin_mess,$from,"-frobertson@marine.rutgers.edu");
      $success    = true;
   }
}

if(isset($success) && $success){
   include HEAD;
?>
<h2>You have successfully registered for the 2006 US GLOBEC Pan-Regional Synthesis Meeting. Thank you.<br/><br />You should receive a confirmation email shortly. If you do not receive a confirmation please contact the webmaster via the link at the bottom of all U.S. GLOBEC webpages.</h2>
<?
   include FOOT;
   exit;
}

$data  = $_POST;
$times = $data['times'];

include HEAD;
?>
<?
if($_POST['but'] == "Submit" && !$audit && $valid) echo '<h2><font color="red">You must enter a correct validation code</font></h2>';
echo $indication;
?>
<br />
<h1>Registration</h1>
<form name="mainform" method="post" action="<?=SYNTH06_REGISTER?>">
<table>
<?
if(!empty($data['last']))
   $tmp=stripslashes($data['last']);
else
   $tmp='';
?>
<tr>
   <td valign="top">
      <font class="NORMAL">Last name: </font>
   </td>
   <td>
      <input type="text" name="last" value="<?=$tmp?>" size="40" maxlength="255" onkeypress="return noenter(this,event)" />
   </td>
</tr>
<?
if(!empty($data['first']))
   $tmp=stripslashes($data['first']);
else
   $tmp='';
?>
<tr>
   <td valign="top">
      <font class="NORMAL">First Name: </font>
   </td>
   <td>
      <input type="text" name="first" value="<?=$tmp?>" size="40" maxlength="255" onkeypress="return noenter(this,event)" />
   </td>
</tr>
<?
if(!empty($data['institution']))
   $tmp=stripslashes($data['institution']);
else
   $tmp='';
?>
<tr>
   <td valign="top">
      <font class="NORMAL">Institution: </font>
   </td>
   <td>
      <input type="text" name="institution" value="<?=$tmp?>" size="40" maxlength="255" onkeypress="return noenter(this,event)" />
   </td>
</tr>
<?
if(!empty($data['email']))
   $tmp=stripslashes($data['email']);
else
   $tmp='';
?>
<tr>
   <td valign="top">
      <font class="NORMAL">email: </font>
   </td>
   <td>
      <input type="text" name="email" value="<?=$tmp?>" size="40" maxlength="255" onkeypress="return noenter(this,event)" />
   </td>
</tr>
<tr>
   <td valign="top">
      <font class="NORMAL">Times attending:<br />check all that<br />apply</font>
   </td>
   <td>
      <table border="1">
      <tr>
         <td width="90">&nbsp;</td>
         <td width="40" align="center">AM</td>
         <td width="40" align="center">PM</td>
      </tr>
      <tr>
         <td>Monday</td>
         <td>&nbsp;</td>
         <td align="center"><input type="checkbox" name="m_p" <?if($data['m_p']=='on') echo 'checked';?>></td>
      </tr>
      <tr>
         <td>Tuesday</td>
         <td align="center"><input type="checkbox" name="t_a" <?if($data['t_a']=='on') echo 'checked';?>></td>
         <td align="center"><input type="checkbox" name="t_p" <?if($data['t_p']=='on') echo 'checked';?>></td>
      </tr>
      <tr>
         <td>Wednesday</td>
         <td align="center"><input type="checkbox" name="w_a" <?if($data['w_a']=='on') echo 'checked';?>></td>
         <td align="center"><input type="checkbox" name="w_p" <?if($data['w_p']=='on') echo 'checked';?>></td>
      </tr>
      <tr>
         <td>Thursday</td>
         <td align="center"><input type="checkbox" name="th_a" <?if($data['th_a']=='on') echo 'checked';?>></td>
         <td align="center"><input type="checkbox" name="th_p" <?if($data['th_p']=='on') echo 'checked';?>></td>
      </tr>
      </table>
   </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
   <td colspan="2" align="center"><b>*Working Groups</b></td>
<?
if(!empty($data['groups1']))
   $tmp=stripslashes($data['groups1']);
else
   $tmp='';
?>
<tr>
   <td valign="top" colspan="2">
   <table>
   <tr>
      <td>1st choice: </td>
      <td><select name="groups1">
            <option value="">-----Select One-----</option>
            <option value="1" <?if($data['groups1'] == 1) echo 'selected'?>>Circulation</option>
            <option value="2" <?if($data['groups1'] == 2) echo 'selected'?>>Nutrients plus Phytoplankton</option>
            <option value="3" <?if($data['groups1'] == 3) echo 'selected'?>>Zooplankton</option>
            <option value="4" <?if($data['groups1'] == 4) echo 'selected'?>>fish</option>
          </select>
      </td>
      <td>2nd choice: </td>
      <td><select name="groups2">
            <option value="">-----Select One-----</option>
            <option value="1" <?if($data['groups2'] == 1) echo 'selected'?>>Circulation</option>
            <option value="2" <?if($data['groups2'] == 2) echo 'selected'?>>Nutrients plus Phytoplankton</option>
            <option value="3" <?if($data['groups2'] == 3) echo 'selected'?>>Zooplankton</option>
            <option value="4" <?if($data['groups2'] == 4) echo 'selected'?>>fish</option>
          </select>
      </td>
   </tr>
   </table>
   </td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
   <td>
      <font class="NORMAL">Authentication: </font>
   </td>
   <td>
      please enter the numbers you see in the image below.
      <img width="120" height="30" src="button.php" border="1" />
      <br />
      <input maxlength="5" SIZE="5" name="userdigit" type="text" value="" />
      <br />
   </td>
</tr>
<tr>
   <td>&nbsp;</td>
   <td>
      <input type="submit" name="but" value="Submit" />
   </td>
</tr>
</table>
</form>
<hr />
<b>NOTES:</b><br />
*: On Tuesday afternoon we will be breaking the workshop into 4 working groups split along trophic levels and circulation. Please choose 2 groups. We will do our best to get you into your first choice group.
<?
include FOOT;
?>
