//include("myshootflow/conn.php");
include("myshootflow/conn.php");
include("myshootflow/functions.php");
$dbconn = mysqli_connect(_db_host, _db_user, _db_pass,_db_name);
$uid = preg_replace('/[^0-9]/', '', $_REQUEST['uid']);
// default styles
$background_color = "#e2e3e5";
$text_color = "#404041";
$field_color = "#404041";
$field_text_color = "#e2e3e5";
$field_font_size = "11px";
$field_font_weight = "bold";
$title = "I want to find out more";
$title_color = "#404041";
$title_size = "16px";
$title_weight = "bold";
$button_text = "Go";
$button_color = "#4e4e50";
$button_text_color = "#ffffff";
$button_hover_color = "#e26244";
$button_hover_text_color = "#ffffff";
// check for custom styles
$get_styles = mysqli_query($dbconn,"SELECT * FROM leadform_styles WHERE user_id = '$uid' LIMIT 1");
if(mysqli_num_rows($get_styles) > 0){
$srow = mysqli_fetch_assoc($get_styles);
if(!empty($srow['background_color'])){ $background_color = $srow['background_color']; }
if(!empty($srow['text_color'])){ $text_color = $srow['text_color']; }
if(!empty($srow['field_color'])){ $field_color = $srow['field_color']; }
if(!empty($srow['field_text_color'])){ $field_text_color = $srow['field_text_color']; }
if(!empty($srow['field_font_size'])){ $field_font_size = $srow['field_font_size']; }
if(!empty($srow['field_font_weight'])){ $field_font_weight = $srow['field_font_weight']; }
$title = $srow['title']; // allow this to be emtpy
if(!empty($srow['title_color'])){ $title_color = $srow['title_color']; }
if(!empty($srow['title_size'])){ $title_size = $srow['title_size']; }
if(!empty($srow['title_weight'])){ $title_weight = $srow['title_weight']; }
if(!empty($srow['button_text'])){ $button_text = $srow['button_text']; }
if(!empty($srow['button_color'])){ $button_color = $srow['button_color']; }
if(!empty($srow['button_text_color'])){ $button_text_color = $srow['button_text_color']; }
if(!empty($srow['button_hover_color'])){ $button_hover_color = $srow['button_hover_color']; }
if(!empty($srow['button_hover_text_color'])){ $button_hover_text_color = $srow['button_hover_text_color']; }
}
?>
");
$citystart = $citystart + 35;
$pgdata = substr($pgdata, $citystart);
$cityend = strpos($pgdata, " ");
$city = substr($pgdata, 0, $cityend);
$statestart = strpos($pgdata, " ");
$statestart = $statestart + 29;
$pgdata = substr($pgdata, $statestart);
$stateend = strpos($pgdata, " ");
$state = substr($pgdata, 0, $stateend);
}
$zipinfo['city'] = $city;
$zipinfo['state'] = $state;
return $zipinfo;
}
// initionalize some vars
$firstname = "";
$lastname = "";
$email = "";
$zip = "";
$contact_firstname = "";
$contact_lastname = "";
$contact_email = "";
$contact_zip = "";
$contact_phone = "";
$contact_city = "";
$contact_state = "";
$groom_firstname = "";
$groom_lastname = "";
$groom_email = "";
$groom_zip = "";
$groom_phone = "";
$groom_city = "";
$groom_state = "";
$bride_firstname = "";
$bride_lastname = "";
$bride_email = "";
$bride_zip = "";
$bride_phone = "";
$bride_city = "";
$bride_state = "";
$client_budget = "";
$wedding_date = "0000-00-00 00:00:00";
$email2 = "";
$fiance_firstname = "";
$fiance_lastname = "";
$ceremony_location = "";
$how_hear = "";
$interest_rank = "";
$client_notes = "";
$city = "";
$state = "";
$answer = "";
if(isset($_POST['lead'])){
if(isset($_POST['firstname'])){ $firstname = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z\'.-]/', '', $_POST['firstname'])); }
if(isset($_POST['lastname'])){ $lastname = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z\'.-]/', '', $_POST['lastname'])); }
if(isset($_POST['fiance_firstname'])){ $fiance_firstname = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z\'.-]/', '', $_POST['fiance_firstname'])); }
if(isset($_POST['fiance_lastname'])){ $fiance_lastname = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z\'.-]/', '', $_POST['fiance_lastname'])); }
if(isset($_POST['ceremony_location'])){ $ceremony_location = mysqli_real_escape_string($dbconn, $_POST['ceremony_location']); }
if(isset($_POST['email'])){ $email = mysqli_real_escape_string($dbconn,filter_var($_POST['email'], FILTER_SANITIZE_EMAIL)); }
if(isset($_POST['email2'])){ $email2 = mysqli_real_escape_string($dbconn,filter_var($_POST['email2'], FILTER_SANITIZE_EMAIL)); }
if(isset($_POST['phone'])){ $phone = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9+.-]/', '', $_POST['phone'])); }
if(isset($_POST['contact_type'])){ $contact_type = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z]/', '', $_POST['contact_type'])); }
if(isset($_POST['client_budget'])){ $client_budget = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9a-zA-Z $,._-]/', '', $_POST['client_budget'])); }
if(isset($_POST['wedding_date'])){ $wedding_date = mysqli_real_escape_string($dbconn, date("Y-m-d H:i:s", strtotime($_POST['wedding_date']))); }
if(isset($_POST['question'])){ $question_array = $_POST['question']; }
if(isset($_POST['answer'])){ $answer_array = $_POST['answer']; }
if($wedding_date < "1999-12-31 00:00:00"){ // this is if the date is entered too poorly
$errors[] = "Wedding date not in acceptable format.";
}
if(isset($_POST['uid'])){
$user_id = mysqli_real_escape_string($dbconn,preg_replace('/[^0-9]/', '', $_POST['uid']));
if(empty($user_id)){
$errors[] = "Unidentified Photographer";
}
}else{
$errors[] = "Unidentified Photographer";
}
if(empty($firstname)){
$errors[] = "Missing First Name";
}
if(empty($lastname)){
$errors[] = "Missing Last Name";
}
if(empty($email)){
$errors[] = "Missing Email";
}else{
if($email == $email2){ // do they match?
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { // Is email valid?
$errors[] = "$email is not a valid email address";
}
}else{
$errors[] = "Email addresses do not match";
}
}
$stamp = date("Y-m-d H:i:s"); // current date/time
if(isset($errors)){
echo 'Some errors occured.
';
foreach($errors as $error){
echo ''.$error.' ';
}
echo " \n";
echo 'Go Back
';
}else{
// process zip
if(!empty($zip)){
$ziplookup = get_zip_info($zip);
$city = $ziplookup['city'];
$state = $ziplookup['state'];
}
$contact_firstname = $firstname;
$contact_lastname = $lastname;
$contact_email = $email;
$contact_phone = $phone;
if($contact_type == "groom"){
$groom_firstname = $firstname;
$groom_lastname = $lastname;
$groom_email = $email;
$groom_phone = $phone;
$bride_firstname = $fiance_firstname;
$bride_lastname = $fiance_lastname;
}
if($contact_type == "bride"){
$bride_firstname = $firstname;
$bride_lastname = $lastname;
$bride_email = $email;
$bride_phone = $phone;
$groom_firstname = $fiance_firstname;
$groom_lastname = $fiance_lastname;
}
$save_lead = mysqli_query($dbconn,"INSERT INTO clients (client_id,
user_id,
bride_firstname,
bride_lastname,
bride_city,
bride_state,
bride_zip,
bride_email,
bride_phone,
groom_firstname,
groom_lastname,
groom_city,
groom_state,
groom_zip,
groom_email,
groom_phone,
contact_firstname,
contact_lastname,
contact_city,
contact_state,
contact_zip,
contact_email,
contact_phone,
how_hear,
client_notes,
interest_rank,
client_budget,
entry_date,
status)
VALUES ('',
'$user_id',
'$bride_firstname',
'$bride_lastname',
'$bride_city',
'$bride_state',
'$bride_zip',
'$bride_email',
'$bride_phone',
'$groom_firstname',
'$groom_lastname',
'$groom_city',
'$groom_state',
'$groom_zip',
'$groom_email',
'$groom_phone',
'$contact_firstname',
'$contact_lastname',
'$contact_city',
'$contact_state',
'$contact_zip',
'$contact_email',
'$contact_phone',
'$how_hear',
'$client_notes',
'$interest_rank',
'$client_budget',
'$stamp',
'1')");
$client_id = mysqli_insert_id($dbconn);
if(!$save_lead){
echo 'There was an error saving the information.
';
}else{
$save_wedding_date = mysqli_query($dbconn,"INSERT INTO wedding_info(user_id, client_id, wedding_date, ceremony_location)VALUES('$uid','$client_id','$wedding_date','$ceremony_location')");
// save answers to the custom questions ///////////////////////////////////////////////////////////////
if(!empty($question_array)){
foreach($question_array as $x => $question){
$selections = "";
$question = mysqli_real_escape_string($dbconn,$question);
if(!empty($answer_array[$x])){ $answer = mysqli_real_escape_string($dbconn,$answer_array[$x]); }
if($answer != ""){ // if it isn't blank
$questions_query_array[] = "('$user_id','$client_id','$question','$answer','$stamp')";
}
}
}
if(isset($questions_query_array) && !empty($questions_query_array)){
$questions_query = implode(",",$questions_query_array);
}
$save_answers = mysqli_query($dbconn,"INSERT INTO leadform_answers (user_id, client_id, question, answer, date_added) VALUES $questions_query ");
// end save answers to the custom questions ///////////////////////////////////////////////////////////////
echo 'Thank you for your interest. You will hear from us soon.
';
// send an email to the photog
$get_email = mysqli_query($dbconn,"SELECT studio_email FROM users WHERE user_id = '$uid'");
if(mysqli_num_rows($get_email) > 0){
$prow = mysqli_fetch_assoc($get_email);
$studio_email = $prow['studio_email'];
$lead_info = "";
// assembly lead info
$lead_info .= 'Wedding Date: '.date("F j, Y", strtotime($wedding_date));
$lead_info .= " ";
$lead_info .= " ";
$lead_info .= 'The main contact is: '.ucfirst($contact_type);
$lead_info .= " ";
if($contact_type == "groom"){
$lead_info .= $groom_firstname.' '.$groom_lastname;
}elseif($contact_type == "bride"){
$lead_info .= $bride_firstname.' '.$bride_lastname;
}else{
$lead_info .= 'Contact Name: '.$contact_firstname.' '.$contact_lastname;
}
$lead_info .= " ";
if(!empty($contact_email)){
$lead_info .= 'Email: '.$contact_email;
}
$lead_info .= " ";
if(!empty($contact_phone)){
$lead_info .= 'Phone: '.preg_replace("/^(\d{3})(\d{3})(\d{4})$/", "$1-$2-$3", $contact_phone);
}
$lead_info .= " ";
$lead_info .= " ";
if($contact_type == "groom"){
$lead_info .= 'Bride: '.$bride_firstname.' '.$bride_lastname;
}elseif($contact_type == "bride"){
$lead_info .= 'Groom: '.$groom_firstname.' '.$groom_lastname;
}else{
$lead_info .= 'Bride: '.$bride_firstname.' '.$bride_lastname;
$lead_info .= " ";
$lead_info .= 'Groom: '.$groom_firstname.' '.$groom_lastname;
}
$lead_info .= " ";
$lead_info .= " ";
if(!empty($ceremony_location)){
$lead_info .= 'Ceremony Location: '.$ceremony_location;
}
$lead_info .= " ";
$lead_info .= " ";
if(!empty($ceremony_location)){
$lead_info .= 'Client Budget: '.$client_budget;
}
if(!empty($question_array)){
foreach($question_array as $x => $question){
$lead_info .= " ";
$lead_info .= " ";
$lead_info .= $question.': '.$answer_array[$x];
}
}
$subject = "You have a new lead in ShootFlow!";
$message = "The ShootFlow Ninjas have detected a new lead has filled out your lead form.\n ".
"\n".$lead_info;
send_email($studio_email,"ShootFlow",$studio_email,$subject,$message,"");
// $mailer = new Email;
// $mailer->ToMail = $studio_email;
// $mailer->FromMail = "shootflow@shootflow.com";
// $mailer->FromName = "ShootFlow";
// $mailer->Subject = "You have a new lead in ShootFlow!";
// $mailer->Message = "The ShootFlow Ninjas have detected a new lead has filled out your lead form.\n ".
// "\n".$lead_info;
//
// $mailer->SendMail();
}
}
}
}else{
$get_studio_name = mysqli_query($dbconn,"SELECT studio_name FROM users WHERE user_id = '$uid'");
if(mysqli_num_rows($get_studio_name) > 0){
$srow = mysqli_fetch_assoc($get_studio_name);
$studio_name = $srow['studio_name'];
}
echo '';
echo ''.$title.' ';
echo '';
echo ' ';
}
?>