<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
 // Need to remove the requirement for login
    if (!defined('START_SESSION')) { define('START_SESSION', true); }
	 
  require_once "cmsAdmin/lib/viewer_functions.php";
  $CMS_USER = getCurrentUserFromCMS(); 
 ?>
<?php  
 if (@$_POST['formSubmit'])   {
 // if ( @$_REQUEST['formSubmit']) {	
      // error checking
    $errorsAndAlerts = "";
    if (!@$_REQUEST['attendee_number'] && !@$_REQUEST['first_name'])                { $errorsAndAlerts .= "You must enter your First Name<br/>\n"; }
	if (!@$_REQUEST['attendee_number'] && !@$_REQUEST['last_name'])                { $errorsAndAlerts .= "You must enter your Last Name<br/>\n"; }
    if (!@$_REQUEST['attendee_number'] && !@$_REQUEST['email_address'])                   { $errorsAndAlerts .= "You must enter your E-mail Address<br/>\n"; }
    else if(!@$_REQUEST['attendee_number'] && !isValidEmail(@$_REQUEST['email_address'])) { $errorsAndAlerts .= "Please enter a valid E-mail address (example: user@example.com)<br/>\n"; }
   $count = mysql_select_count_from('attendance_test', "'".mysql_escape($_REQUEST['email_address'])."' IN (email_address)");
   $count2 = mysql_select_count_from('attendance_test', "'".mysql_escape($_REQUEST['attendee_number'])."' IN (num)");    
 if (!@$count2 != 0)                   { $errorsAndAlerts .= "Sorry, the Attendee ID Number you entered, doesn't match our records, please try again or entrer your name and email address. <br/>\n"; } ?>
<?php
	
// turn off strict mysql error checking for: STRICT_ALL_TABLES
  mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

  
  
    // Check for first name, last name, and email address. Insert new record if email address is not found.
	   if ($count == 0 && !$errorsAndAlerts) {  
            @$_REQUEST['first_name']=ucwords(@$_REQUEST['first_name']);		
			@$_REQUEST['last_name']=ucwords(@$_REQUEST['last_name']);	
	 $lecturedate =  date(" m-Y, ") ;				
     mysql_query("INSERT INTO `{$TABLE_PREFIX}attendance_test` SET
                      first_name         = '".mysql_escape( $_REQUEST['first_name'] )."',
					  last_name         = '".mysql_escape( $_REQUEST['last_name'] )."',
					  email_address            = '".mysql_escape( $_REQUEST['email_address'] )."',
					  salon_name = 'MMM',
					  mmm_attended = '$lecturedate',
					  updatedByUserNum = '".mysql_escape( $CMS_USER['num'] )."',	 
					  createdDate      = NOW(),
                      updatedDate      = NOW()")
                    or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $userNum = mysql_insert_id();
    // on success
      unset($_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']); // clear form
      $errorsAndAlerts = "Thanks, we've signed you in, and we're ready for the next guest.";
    }
     
   
	// Check for first name, last name, and duplicate email address. Update record if email address is found.
      if (!@$_REQUEST['attendee_number'] && $count > 0 && !$errorsAndAlerts) {  
		    @$_REQUEST['first_name']=ucwords(@$_REQUEST['first_name']);		
			@$_REQUEST['last_name']=ucwords(@$_REQUEST['last_name']);	
	 $lecturedate =  date("m-Y, ") ;
		 		
      $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
                     first_name         = '".mysql_escape( $_REQUEST['first_name'] )."',
					 last_name         = '".mysql_escape( $_REQUEST['last_name'] )."',
				     salon_name = 'MMM',
				     mmm_attended = CONCAT(mmm_attended, '$lecturedate'),
					 updatedByUserNum = '".mysql_escape( $CMS_USER['num'] )."',
                     updatedDate      = NOW()
                    WHERE email_address = '".mysql_escape( $_REQUEST['email_address'] )."'";
      mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $userNum = mysql_insert_id();

      // on success
      unset($_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']); // clear form
      $errorsAndAlerts = "Thanks, we've signed you in, and we're ready for the next guest.";
    }
	
	
	// Check for attendee ID number. Update record if ID number is found.
      if (@$_REQUEST['attendee_number']  && !$errorsAndAlerts) {  
		
	 $lecturedate =  date("m-Y, ") ;
		 		
      $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
                    
				     salon_name = 'MMM',
				     mmm_attended = CONCAT(mmm_attended, '$lecturedate'),
					 updatedByUserNum = '".mysql_escape( $CMS_USER['num'] )."',
                     updatedDate      = NOW()
					  WHERE num = '".mysql_escape( $_REQUEST['attendee_number'] )."'";
					// Placeholder variable which should pull the attendees first name from the updated record. 
					  $first_name = 'ATTENDEE\'S FIRST NAME' ;
                     mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
      $userNum = mysql_insert_id();

      // on success
      unset($_REQUEST['attendee_number'], $_REQUEST['first_name'], $_REQUEST['last_name'], $_REQUEST['email_address']); // clear form
     // Should insert attendee's first_name in the $first _name variable. 
	  $errorsAndAlerts = "Thanks, $first_name we've signed you in, and we're ready for the next guest.";
    }
    }
	
 /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */	  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/hsphere/local/home/a887307/elleschorrphotography.com/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records
  list($attendance_testRecords, $attendance_testMetaData) = getRecords(array(
    'tableName'   => 'attendance_test',
  ));
  
  
?>

<!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>Mixed / Multi-Media Salon Sign In</title>
<link href="css/elle.css.php" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#000000">
<?php if (@$errorsAndAlerts): ?>
<div ><br/>
  <?php echo $errorsAndAlerts; ?><br/>
  <br/>
</div>
<?php endif ?>
<form action="" method="post" name="registrationForm">
  <input type="hidden" value="1" name="formSubmit">
  <table width="850" align="center">
    <tr>
      <td colspan="2" align="center" class="Heading-Text"><h1><br />
          <br />
          WELCOME TO<br />
          THE MIXED /MULTI-MEDIA SALON</h1>
        <h2>PLEASE SIGN IN:</h2>
        <span class="Large-Text">Suggested Donation $10</span><br />
        <br /></td>
    </tr>
  </table>
  <table width="550" align="center">
    <tr>
      <td colspan="2" class="Medium-Text">EXPRESS SIGN IN: If you have an Attendee ID Number, just enter it and click/tap the submit button and you'll automatically be signed in.<br />
        <br /></td>
    </tr>
    <tr>
      <td class="Medium-Text">Attendee ID Number</td>
      <td><input class="Medium-Text" type="text" id="attendee" name="attendee_number" value="<?php echo htmlspecialchars(@$_REQUEST['attendee_number']); ?>"  /></td>
    </tr>
    <tr>
      <td class="Medium-Text">First Name</td>
      <td><input class="Medium-Text" type="text" id="first" name="first_name" value="<?php echo htmlspecialchars(@$_REQUEST['first_name']); ?>"  /></td>
    </tr>
    <tr>
      <td class="Medium-Text">Last Name</td>
      <td><input  class="Medium-Text" type="text" id="last" name="last_name" value="<?php echo htmlspecialchars(@$_REQUEST['last_name']); ?>"  /></td>
    </tr>
    <tr>
      <td class="Medium-Text">E-mail Address</td>
      <td><input type="text" class="Medium-Text" id="email" name="email_address" value="<?php echo htmlspecialchars(@$_REQUEST['email_address']); ?>"  /></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><br/>
        <br/>
        <input name="submitregistration" id="signup" class="Heading-Text" type="submit" value="Click/Tap To Submit" /></td>
    </tr>
  </table>
</form>
</body>
</html>