<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/allbrigh/public_html/','','../','../../','../../../');
  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 from 'products'
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'loadUploads' => true,
    'allowSearch' => true,
  ));

?>


<?php
  // process form
  if (@$_REQUEST['submitForm']) {

    // error checking
    $errorsAlerts = "";
    if (!@$_REQUEST['name'])            { $errorsAlerts .= "Please enter your name!<br/>\n"; }
    if (!@$_REQUEST['telephone'])        { $errorsAlerts .= "Please enter your phone number!<br/>\n"; }
    if (!@$_REQUEST['email'])            { $errorsAlerts .= "Please enter your email!<br/>\n"; } else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAlerts .= "Please enter a valid email (example: user@example.com)<br/>\n"; }
    if (!@$_REQUEST['product'])        { $errorsAlerts .= "Please select a product!<br/>\n"; }
    if (!@$_REQUEST['message'])        { $errorsAlerts .= "Please enter a message!<br/>\n"; }

      // send email user
    if (!$errorsAlerts) {
        $from        = $_REQUEST['email'];
        $to          = "webmaster@thenetgirl.com"; // ENTER YOUR EMAIL ADDRESS HERE
          }
        $subject     = "Product Inquiry";
        $message     = <<<__TEXT__

<div style='padding:24px; font-size:14px; font-family:Verdana; color:#000; border:#999999 solid 1 px;'>
<strong>Name:</strong> {$_REQUEST['name']}<br />
<strong>Phone Number:</strong> {$_REQUEST['telephone']}<br />
<strong>Email:</strong> {$_REQUEST['email']}<br /><br />
<strong>Product:</strong> {$_REQUEST['product']}<br /><br />
<strong>Message:</strong> {$_REQUEST['message']}<br /><br />
</div>

__TEXT__;
 
     $mailErrors = sendMessage(array(
       'to'      =>  $to,
       'from'    =>  $from,
       'subject' =>  $subject,
       'html'    =>  $message,
       
     ));
     
     if ($mailErrors) { die("Error sending email: $mailErrors"); }

      //
      $errorsAlerts = "<span style='color:#990000; font-size:14px; font-family:Verdana;'>Thank you for contacting us. We will be in touch with you very soon.</span>";
      $_REQUEST = array(); // clear form values
      
}   // end form
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Product Inquiry</title>
 
 <style>
 
 .divf
{
border:1px solid #5B6D24;
padding:5px 5px; 
width:360px;
border-radius:10px;
position:relative;
background:#DDECB6;
}
 </style>
</head>

<body>
<div align="center">
 <div style="width:360px;">
<div  class="divf">

	<b><font face="Verdana">PRODUCT INQUIRY<br>
	</font>
 
<font color="#800000" face="Verdana">*Required</font></b>
<form method="POST" action="">
<input type="hidden" name="submitForm" value="1" />
<?php if (@$errorsAlerts): ?>
  <p style="color:#990000; font-size:14px; font-weight:bold; font-family:Verdana;"><?php echo $errorsAlerts; ?><br /></p>
<?php endif ?>

<div><div style="width:100px; float:left;">
<label for="name" style="font-size:14px; font-weight:bold; font-family:Verdana; margin-right:6px;">Name</label></div>
<input type="text" name="name" size="32" value="<?php echo htmlspecialchars(@$_REQUEST['name']); ?>"/></div> 
<div style="clear:both"></div>

<div><div style="width:100px; float:left;">
<label for="email" style="font-size:14px; font-weight:bold; font-family:Verdana; margin-right:6px;">Email</label></div>
<input type="text" name="email" size="32" value="<?php echo htmlspecialchars(@$_REQUEST['email']); ?>"/></div> 
<div style="clear:both"></div>
 
<div><div style="width:100px; float:left;">
<label for="telephone" style="font-size:14px; font-weight:bold; font-family:Verdana; margin-right:6px;">Phone</label></div>
<input type="text" name="telephone" size="32" value="<?php echo htmlspecialchars(@$_REQUEST['telephone']); ?>"/></div>
 <div style="clear:both"></div>

<div><div style="width:100px; float:left;">
<label for="product" style="font-size:14px; font-weight:bold; font-family:Verdana; margin-right:6px;">Product</label></div>
 <select name="product">
      <option value="">Select Product Name</option>
     
      <?php foreach ($productsRecords as $value => $label): ?> 
      <option value="<?php echo $value; ?>" <?php selectedIf($value, @$_REQUEST['product']) ?> ><?php echo $label; ?></option>
      <?php endforeach ?> 
    </select>
</div> <div style="clear:both"></div>

<div><div style="width:100px; float:center; margin-top:6px;">
<label for="message" style="font-size:14px; font-weight:bold; font-family:Verdana; margin-right:6px;">Question</label></div>
<textarea name="message" rows="4" cols="30" style="border:#532314 solid 1px; padding:6px; color:#000;"><?php echo htmlspecialchars(@$_REQUEST['message']); ?></textarea></div> 
<div style="clear:both"></div>

<input type="submit" name="submit" value="Send Product Inquiry" style="margin-left:40px; margin-top:6px;" />

</form>
</div>

</body>
</html>