<?php header('Content-type: text/html; charset=utf-8'); ?>

<?php
  // This version uses salon_name and is waiting for 2 solutions from forum
 
    if (!defined('START_SESSION')) { define('START_SESSION', true); }
	 
  require_once "cmsAdmin/lib/viewer_functions.php";
  $CMS_USER = getCurrentUserFromCMS(); 
 ?>
 
<?php    function addValueToListValues($values, $newValue){
    if(!strstr($values, "\t$newValue\t")){
       return $updatedValue = $values.$newValue."\t";
    }else{
      return $values;
    }
  }
  ?>
<?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)

    // The values for AWC = 1, and for MMM = 2
   
    // Check for attendee ID number. Update record if ID number is found.
      if (@$_REQUEST['attendee_number']  && !$errorsAndAlerts) {  
		   	
	 $lecturedate =  date("m-y").'AWC, ' ;
		 		
      $query = "UPDATE `{$TABLE_PREFIX}attendance_test` SET
				    attended = CONCAT(attended, '$lecturedate'),
					 updatedByUserNum = '".mysql_escape( $CMS_USER['num'] )."',
                     updatedDate      = NOW()
					  
	WHERE num = '".mysql_escape( $_REQUEST['attendee_number'] )."'";
		
		$my_var = mysql_get('attendance_test',25);
$updatedValue = addValueToListValues($my_var['salon_name'],'1');
  mysql_update('attendance_test',25, null, array('salon_name' => $updatedValue));
  				    
						
  // Get the attendee's first name from the updated record. 
     $loggedInUser = mysql_get('attendance_test', $_REQUEST['attendee_number']);
     $first_name = @$loggedInUser['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
     $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',
  ));
  
    // load record from 'salon_messages'
  list($salon_messagesRecords, $salon_messagesMetaData) = getRecords(array(
    'tableName'   => 'salon_messages',
    'where'       => '', // load first record
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $salon_messagesRecord = @$salon_messagesRecords[0]; // get first record
  
?>

<!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>Art, Women, and Culture Salon Sign In</title>
<link href="css/elle.css.php" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#000000">
 <table width="75%" border="0" align="center" cellpadding="20">
  <tr><td class="Heading-Text-Yellow" colspan="2"><?php if (@$errorsAndAlerts): ?>
  <?php echo $errorsAndAlerts; ?><?php else : ?>&nbsp;<?php endif ?>
</td>
  </tr>
    <tr>
    <td width="40%" style="text-align:center"> <H2>WELCOME TO<br />
          THE ART, WOMEN, AND CULTURE SALON</h1>
        <h2>PLEASE SIGN IN:</h2>
        <span class="Large-Text">Suggested Donation $10</span><br />
        <br /></td>
    <td width="60%"><form action="" method="post" name="registrationForm">
  <input type="hidden" value="1" name="formSubmit" />
 
  <table 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></td>
  </tr>
</table>
<?php ob_start(); // start capturing output ?>
     
       <?php $welcome_email_message_awc = @$salon_messagesRecord['welcome_email_message_awc'] ?>
      <?php $welcome_email_message_awc = wordwrap($welcome_email_message_mmm, 70); ?> 
      <?php echo $welcome_email_message_awc ?>
     <!-- <br /><br />Just so you know, your Attendee ID number is .<br /><br />
      Next time you come to a salon, you can enter that number and you'll be signed in without having to enter your name and e-mail address. --> 
      <?php $output = ob_get_clean(); // stop capturing output  ?>
	  
      
      <?php 
if (@$welcome_email == 1):?>
<?php $first_name = strtoupper($first_name) ?>
   <?php $the_to = $email_address ?>   
     <?php 
 
 $message = <<<EOF
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type content='text/html; charset=utf-8" />
<style type="text/css">
.special {font-family:Arial; color:  rgb(227,224,219); font-size: 1.0em; font-weight: bold; text-decoration: underline;}
.body-text {font-family:Arial; font-size: 1.0em;}
.heading-text {font-family:Arial; font-size: 1.3em;}
.body-text-yellow {font-family:Arial; color: rgb(255,255,0); font-size: 1.0em;}
.heading-text-yellow {font-family:Arial; color: rgb(255,255,0); font-size: 1.3em; font-weight: bold;}
</style>
</head>
<body bgcolor="#B2A1C7">
<table style='background-color: #B2A1C7;' width='100%' align='center' border='0' >
			  <tr>
    <td align='left' >
	<table style='background-color: #B2A1C7;' width='70%' align='center' border='0' >
			  <tr>
    <td align='left' >
	<div align='center' class='heading-text'><br /><br />WELCOME, $first_name. </div>
 <br /><br />
 <div align='left' class='body-text'>
   $output \r\n<br /

    <br /><br />

Elle Schorr<br />
Salon Facilitator
  </td>
    </tr>
	</table>
	</td>
    </tr>
	</table>
  </body>
</html>
EOF;
 $the_from  = "elleschorr@elleschorrphotography.com";
 $the_subject = "Thanks for attending the Art, Women and Culture Salon";

$mailArray = array( 
'to' => $the_to,
'from' => $the_from,
'subject' => $the_subject,
'html'         => $message 
); 
$errors =  sendMessage($mailArray);
// delay execution by .2 sec
usleep(200000);
// reset max_execution_time to 30 sec
set_time_limit(30);
?>
      
<div align='center' class='heading-text'>A welcome e-mail has been sent to: <?php echo @$the_to ?></div>
  <?php endif; ?>
  
</body>