<?php
require_once "cmsAdmin/lib/viewer_functions.php";   
 if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }


// submit form
if (@$_REQUEST['submit']) {

  // error checking
  $errorsAndAlerts = "";
  if (!@$_REQUEST['name'])    { $errorsAndAlerts .= "Please specify name!<br/>\n"; }
  if (!@$_REQUEST['address'])  { $errorsAndAlerts .= "Please specify address!<br/>\n"; }

  // 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)

  // add record
  if (!@$errorsAndAlerts) {
    mysql_query("INSERT INTO `{$TABLE_PREFIX}auto_referrals` SET
                      name            = '".mysql_real_escape_string( $_REQUEST['name'] )."',
                      address          = '".mysql_real_escape_string( $_REQUEST['address'] )."',
                      city             = '".mysql_real_escape_string( $_REQUEST['city'] )."',
					  state            = '".mysql_real_escape_string( $_REQUEST['state'] )."',
					  zip              = '".mysql_real_escape_string( $_REQUEST['zip'] )."',
			          contact_phone    = '".mysql_real_escape_string( $_REQUEST['contact_phone'] )."',
					  email            = '".mysql_real_escape_string( $_REQUEST['email'] )."',
					  date_of_loss     = '".mysql_real_escape_string( $_REQUEST['date_of_loss'] )."',
                      vehicle_make     = '".mysql_real_escape_string( $_REQUEST['vehicle_make'] )."',
                      vehicle_model    = '".mysql_real_escape_string( $_REQUEST['vehicle_model'] )."',
                      vehicle_year     = '".mysql_real_escape_string( $_REQUEST['vehicle_year'] )."',
                      notes            = '".mysql_real_escape_string( $_REQUEST['notes'] )."',



                      createdDate      = NOW(),
                      updatedDate      = NOW(),
                      createdByUserNum = 'num',
                      updatedByUserNum = 'num'")
    or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
    $recordNum = mysql_insert_id();

    // display thanks message and clear form
    $errorsAndAlerts = "Thanks, we've added that record! <br/><a href='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>Click here to continue</a>";
    $_REQUEST = array();
  }

}

?>
 <?php include "include_header.php"; ?>

<form method="post" action="">
<input type="hidden" name="submit" value="1" />

<p><font size="4">Add Referral</font></p>
<?php if (@$errorsAndAlerts): ?>
  <div style="color: red; font-weight: bold; font-size: 16px;"><br/>
    <?php echo $errorsAndAlerts; ?><br/>
  </div>
<?php endif ?>


<div align="center">


<table border="0" cellspacing="0" cellpadding="2" width="50%">
 <tr>
  <td valign="top" width="30%"><b><font size="2" face="Verdana">Priority</font></b></td>
  <td><select name="priority" class="dropdown" id="type" size="1" style="font-family: Verdana; color: #000000; font-size: 10pt" > 
<option selected>Select Priority</option>
  <?php
  $schema       = loadSchema('auto_referrals');  
  $fieldSchema  = $schema['priority'];  
  $fieldOptions = getListOptionsFromSchema($fieldSchema);
  
  foreach ($fieldOptions as $valueAndLabel) {  
    list($value,$label) = $valueAndLabel;
    $encodedValue = htmlspecialchars($value);  
    $encodedLabel = htmlspecialchars($label);  
    print "<option value=\"$encodedValue\">$encodedLabel</option>\n";  
  }  
?>
	
</select></td>
	</tr>
 <tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>Name</b></font></td>
  <td>
	<input type="text" name="name" value="<?php echo htmlspecialchars(@$_REQUEST['name']) ?>" size="60" /></td>
</tr>
 <tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>Address</b></font></td>
  <td><input type="text" name="address" value="<?php echo htmlspecialchars(@$_REQUEST['address']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>City</b></font></td>
  <td><input type="text" name="city" value="<?php echo htmlspecialchars(@$_REQUEST['city']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>State</b></font></td>
  <td><input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>Zip</b></font></td>
  <td><input type="text" name="zip" value="<?php echo htmlspecialchars(@$_REQUEST['zip']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>Contact Phone</b></font></td>
  <td><input type="text" name="contact_phone" value="<?php echo htmlspecialchars(@$_REQUEST['contact_phone']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><b><font face="Verdana" size="2">Email</font></b></td>
  <td><input type="text" name="email" value="<?php echo htmlspecialchars(@$_REQUEST['email']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><b><font face="Verdana" size="2">Date of Loss</font></b></td>
  <td><input type="text" name="date_of_loss" value="<?php echo htmlspecialchars(@$_REQUEST['date_of_loss']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><font face="Verdana" size="2"><b>Vehicle make</b></font></td>
  <td><input type="text" name="vehicle_make" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_make']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><b><font face="Verdana" size="2">V</font></b><font face="Verdana" size="2"><b>ehicle model</b></font></td>
  <td><input type="text" name="vehicle_model" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_model']) ?>" size="60" /></td>
</tr>
<tr>
  <td valign="top" width="30%"><b><font face="Verdana" size="2">V</font></b><font face="Verdana" size="2"><b>ehicle year</b></font></td>
  <td><input type="text" name="vehicle_year" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_year']) ?>" size="60" /></td>
</tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Notes</b></font></td> 
<td><textarea name="notes" cols="37" rows="4"><?php echo htmlspecialchars(@$_REQUEST['notes']) ?></textarea></td> 
</tr> 

</table></div>
<p align="center">


<input type="submit" name="add" value="Add Referral &gt;&gt;" />

</p>

</form>
   <?php include "include_footer.php"; ?>