0byt3m1n1
Path:
/
data
/
51
/
2
/
82
/
137
/
2408789.shuffle
/
user
/
2641263
/
htdocs
/
contest
/
[
Home
]
File: index.php
<?php $local_debug = false; require('../wp-load.php'); require '../phpmailer/class.phpmailer.php'; $mail = new PHPMailer; // set global debug options if ($local_debug) { $wpdb->show_errors(); } $entry_expires = get_field('close_date'); //'2015-10-13 00:00:00'; function assignPageTitle(){ return "Contest Entry Form - Union Bank"; } add_filter('wp_title', 'assignPageTitle'); function get_max_size () { if (return_bytes(ini_get('post_max_size')) < return_bytes(ini_get('upload_max_filesize'))) return ini_get('post_max_size'); else return ini_get('upload_max_filesize'); } function return_bytes($val) { // Thanks, PHP documentation! $val = trim($val); $last = strtolower($val[strlen($val)-1]); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } // form validation 2015-08-28 function form_validate(&$data, $name, $type) { global $errors; $commands = explode(',', $type); foreach($commands as $command ) { $args = explode('=', $command); switch ($args[0]) { case 'exist': if (!$data) // must exist and must not be zero $errors[] = 'Please enter your '. $name; break; case 'exist-strict': if (!isset($data)) //must exist, literal zero is acceptable $errors[] = 'Please enter your '. $name; break; case 'sanitize': if (!preg_match('~^[-\'\.,0-9A-Za-z /&]*$~', $data)) $errors[] = $name. ' may not contain symbols.'; break; case 'sanitize-numeric-us': if (preg_match('~^[-\.,0-9 ]*$~', $data)) { $data = intval(str_replace(',', '', $data)); } else { $errors[] = $name. ' must be a number.'; } break; case 'len': if (strlen($data) > $args[1]) $errors[] = $name. ' must be shorter than '. $args[1]. ' charaters.'; break; case 'email': function valid_dot_pos($email) { $str_len = strlen($email); for($i=0; $i<$str_len; $i++) { $current_element = $email[$i]; if($current_element == "." && ($email[$i+1] == ".")) { return false; break; } else { } } return true; } function valid_local_part($local_part) { if(preg_match("/[^a-zA-Z0-9-_@.!#$%&'*\/+-=?^`{\|}~]/", $local_part)) { return false; } else { return true; } } function valid_domain_part($domain_part) { if(preg_match("/[^a-zA-Z0-9-@#\[\].]/", $domain_part)) { return false; } elseif(preg_match("/[@]/", $domain_part) && preg_match("/[#]/", $domain_part)) { return false; } elseif(preg_match("/[\[]/", $domain_part) || preg_match("/[\]]/", $domain_part)) { $dot_pos = strrpos($domain_part, "."); if(($dot_pos < strrpos($domain_part, "]")) || (strrpos($domain_part, "]") < strrpos($domain_part, "["))) { return true; } elseif(preg_match("/[^0-9.]/", $domain_part)) { return false; } else { return false; } } else { return true; } } // trim() the entered E-Mail $str_trimmed = trim($data); // find the @ position $at_pos = strrpos($str_trimmed, "@"); // find the . position $dot_pos = strrpos($str_trimmed, "."); // this will cut the local part and return it in $local_part $local_part = substr($str_trimmed, 0, $at_pos); // this will cut the domain part and return it in $domain_part $domain_part = substr($str_trimmed, $at_pos); if(!isset($str_trimmed) || is_null($str_trimmed) || empty($str_trimmed) || $str_trimmed == "") { $errors[] = 'Please enter a valid e-mail address.'; } elseif(!valid_local_part($local_part)) { $errors[] = 'Please enter a valid e-mail address.'; } elseif(!valid_domain_part($domain_part)) { $errors[] = 'Please enter a valid e-mail address.'; } elseif($at_pos > $dot_pos) { $errors[] = 'Please enter a valid e-mail address.'; } elseif(!valid_local_part($local_part)) { $errors[] = 'Please enter a valid e-mail address.'; } elseif(($str_trimmed[$at_pos + 1]) == ".") { $errors[] = 'Please enter a valid e-mail address.'; } elseif(!preg_match("/[(@)]/", $str_trimmed) || !preg_match("/[(.)]/", $str_trimmed)) { $errors[] = 'Please enter a valid e-mail address.'; } break; case 'terms': if (!$data) // must exist and must not be zero $errors[] = 'You must agree to the terms and conditions.'; break; case 'honeypot': if ($data) $errors[] = 'Please clear the field marked "Do not type here."'; break; case 'file': switch ($data['error']) { case 0: if ($args[1]) { $types = explode(';', $args[1]); if (!in_array($data['type'], $types)) { $output = 'Please use an approved file type for '. $name. '.'; if ($local_debug) { $output .= ' (was '. $data['type']. ')'; } $errors[] = $output; } } break; case 1: case 2: $errors[] = $name. ' size is too large.'; break; case 3: $errors[] = $name. ' did not fully upload. Please try again.'; break; case 4: $errors[] = $name. ' was not sent. Please try again.'; break; default: $errors[] = 'A server error occurred. Please contact Union Bank for assistance. (ERR:FE'. $data['error']. ')'; } break; default: $errors[] = $name. ' did not validate.'; } } } // undo WP's forced magic_quotes foreach ($_POST as $key => $val) { $posted[$key] = stripslashes($val); } get_header(); ?> <article> <div id="post-thumb"><?php if( get_field('contest_header_image', 'options') ) { echo wp_get_attachment_image( get_field('contest_header_image', 'options'), 'full' ); } ?></div> <?php if (strtotime($entry_expires) < time()) { ?> <h1 class="entry-title">Contest Entry</h1> <p>Thank you for your interest in our contest. Unfortunately, the contest submission deadline has passed.</p> <?php } else { if (!empty($posted)) { // Validation form_validate($posted['name'], 'Name', 'exist,sanitize,len=50'); form_validate($posted['address'], 'Address', 'exist,sanitize,len=100'); form_validate($posted['city'], 'City', 'exist,sanitize,len=20'); form_validate($posted['state'], 'State', 'exist,sanitize,len=20'); form_validate($posted['zip'], 'Zip', 'exist,sanitize,len=10'); form_validate($posted['email'], 'E-mail Address', 'email,len=100'); form_validate($posted['phone'], 'Home Phone', 'exist,sanitize,len=20'); form_validate($_FILES['p_file'], 'Photo Upload', 'file=image/tiff;image/jpeg;image/pjpeg'); form_validate($posted['p_title'], 'Photo Title', 'exist,sanitize,len=50'); form_validate($posted['p_loc'], 'Photo Location', 'exist,sanitize,len=50'); form_validate($posted['p_desc'], 'Photo Description', 'exist,len=1000'); form_validate($posted['agree'], 'Agreement', 'terms'); form_validate($posted['nothing'], 'Honey Pot', 'honeypot'); if (isset($posted['nothing']) && $posted['nothing']) { ?> <script type="text/javascript"> ga('send', 'event', 'form', 'honeypot') </script> <?php } if (!isset($errors)) { // validate all else then accept file $_FILES['p_file']['name'] = date('YmdHis'). '_'. $_FILES['p_file']['name']; $uploadfile = './uploads/'. basename($_FILES['p_file']['name']); if (!move_uploaded_file($_FILES['p_file']['tmp_name'], $uploadfile)) { $errors[] = 'A server error occurred. Please contact Union Bank for assistance. (ERR:FM1)'; } } if (!isset($errors)) { // add to database if (!$wpdb->insert( 'ub_contest', array( 'name' => $posted['name'], 'address' => $posted['address'], 'city' => $posted['city'], 'state' => $posted['state'], 'zip' => $posted['zip'], 'e-mail' => $posted['email'], 'phone' => $posted['phone'], 'p_filename' => $_FILES['p_file']['name'], 'p_title' => $posted['p_title'], 'p_loc' => $posted['p_loc'], 'p_desc' => $posted['p_desc'], 'agree' => $posted['agree'], 'timestamp' => date('Y-m-d H:i:s'), 'IP' => $_SERVER['REMOTE_ADDR'] ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', ) )) { $errors[] = 'A server error occurred. Please contact Union Bank for assistance. (ERR:DB1)'; }; } if (!isset($errors)) { // form validates // build message text: to participant $message_body = "A photo was submitted to the Photo Contest.\n\n"; unset($posted['nothing']); unset($posted['p_file']); unset($posted['MAX_FILE_SIZE']); foreach ($posted as $posted_key => $posted_val) { $message_body .= $posted_key. ":\n"; $message_body .= $posted_val. "\n"; $message_body .= "\n"; } $message_body .= "\n"; $message_body .= "----------\n"; $message_body .= 'Timestamp: ' . date('Y-m-d H:i:s'). "\n"; $message_body .= 'IP Address:' . $_SERVER['REMOTE_ADDR']. "\n"; $message_body .= 'User Agent:' . $_SERVER['HTTP_USER_AGENT']. "\n"; $message_body .= "\n\n"; $message_from = 'noreply@unionbankvt.com'; $message_fromname = 'Union Bank Website'; $message_to = 'swhitney@unionbankvt.com'; // *** $message_subject = 'Contest Submission'; if ($local_debug) { $result = true; echo '<code>TO: '. $message_to. "\n"; echo "SUBJECT: ". $message_subject. "\n"; echo "FROM: ". $message_fromname. " <". $message_from. ">\n"; echo "BODY: \n"; echo $message_body. '</code>'; } else { $mail->From = $message_from; $mail->FromName = $message_fromname; $mail->AddAddress($message_to); $mail->IsHTML(false); // Set email format to HTML $mail->Subject = $message_subject; $mail->Body = $message_body; $result = $mail->Send(); } if(!$result) { // e-mail error ?> <div class="apply-online"> <h1 class="entry-title">Thank you for your submission!</h1> <?php the_field('success_message', 'options') ?> </div> <script type="text/javascript"> ga('send', 'event', 'form', 'e-mail error') </script> <?php } else { ?> <div class="apply-online"> <h1 class="entry-title">Thank you for your submission!</h1> <?php the_field('success_message', 'options') ?> </div> <script type="text/javascript"> ga('send', 'event', 'form', 'success') </script> <?php $posted['p_title'] = ''; $posted['p_loc'] = ''; $posted['p_desc'] = ''; $posted['agree'] = ''; } } else { ?> <h1 class="entry-title">Contest Entry Form</h1> <?php } foreach ($posted as $key => $val) { $form[$key] = htmlspecialchars($val); } } else { ?> <h1 class="entry-title">Contest Entry Form</h1> <?php $form['name'] = ''; $form['address'] = ''; $form['city'] = ''; $form['state'] = ''; $form['zip'] = ''; $form['email'] = ''; $form['phone'] = ''; $form['p_title'] = ''; $form['p_loc'] = ''; $form['p_desc'] = ''; $form['agree'] = ''; $form['nothing'] = ''; } if (isset($errors) && $errors) { echo '<ul class="errors">'; foreach ($errors as $errmsg) { echo '<li>'. $errmsg. '</li>'; } echo '</ul>'; } ?> <form id="post" class="acf-form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> <div class="acf-fields acf-form-fields"> <fieldset> <legend>Contact Information</legend> <div class="acf-field acf-field-text"> <div class="acf-label"> <label for="fname">First and Last Name <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="fname" name="name" value="<?php echo $form['name'] ?>" maxlength="50" required autofocus /></div> </div> </div> <div class="acf-field acf-field-text"> <div class="acf-label"> <label for="faddress">Address <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="faddress" name="address" value="<?php echo $form['address'] ?>" maxlength="100" required /></div> </div> </div> <div class="acf-field acf-field-text field-city"> <div class="acf-label"> <label for="fcity">City <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="fcity" name="city" value="<?php echo $form['city'] ?>" maxlength="20" required /></div> </div> </div> <div class="acf-field acf-field-text field-state"> <div class="acf-label"> <label for="fstate">State <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="fstate" name="state" value="<?php echo $form['state'] ?>" maxlength="20" required /></div> </div> </div> <div class="acf-field acf-field-text field-zip"> <div class="acf-label"> <label for="fzip">Zip <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input id="fzip" type="pattern" name="zip" value="<?php echo $form['zip'] ?>" pattern="(\d{5}([\-]\d{4})?)|([A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9])" maxlength="10" placeholder="00000" required /></div> </div> </div> <div class="acf-field acf-field-text"> <div class="acf-label"> <label for="femail">E-mail Address <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input id="femail" type="email" name="email" value="<?php echo $form['email'] ?>" maxlength="100" required placeholder="example@domain.com" /> </div> </div> </div> <div class="acf-field acf-field-text"> <div class="acf-label"> <label for="fphone">Daytime Phone <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input id="fphone" type="tel" name="phone" value="<?php echo $form['phone'] ?>" maxlength="20" placeholder="802-555-5555" required /></div> </div> </div> </fieldset> <fieldset> <legend>Photo Submission</legend> <p>List title, location and description of the photo you are uploading now (you may enter up to 3 times):</p> <div class="acf-field acf-field-file"> <div class="acf-label"> <label for="ffile">Upload File</label> <p class="description">JPEG or TIFF only, <?php echo get_max_size() ?>B Maximum</p> </div> <div class="acf-input"> <div class="acf-file-uploader acf-cf"><input type="hidden" class="hidden" name="MAX_FILE_SIZE" value="<?php echo return_bytes(get_max_size()) ?>" /><input type="file" id="ffile" name="p_file"></div> </div> </div> <div class="acf-field acf-field-text field-photo-title"> <div class="acf-label"> <label for="fptitle">Title <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="fptitle" name="p_title" value="<?php echo $form['p_title'] ?>" maxlength="50" required /></div> </div> </div> <div class="acf-field acf-field-text field-photo-loc"> <div class="acf-label"> <label for="fploc">Location <span class="acf-required">*</span></label> </div> <div class="acf-input"> <div class="acf-input-wrap"><input type="text" id="fploc" name="p_loc" value="<?php echo $form['p_loc'] ?>" maxlength="50" placeholder="Morrisville, VT" required /></div> </div> </div> <div class="acf-field acf-field-textarea"> <div class="acf-label"> <label for="fpdesc">Description <span class="acf-required">*</span></label> </div> <div class="acf-input"> <textarea id="fpdesc" name="p_desc" rows="8" required><?php echo $form['p_desc'] ?></textarea> </div> </div> </fieldset> <fieldset> <legend>Release</legend> <?php the_field('release_text', 'options') ?> <div class="acf-field acf-field-checkbox"> <div class="acf-input"> <ul class="acf-checkbox-list acf-bl"><li><label><input type="checkbox" id="fagree" name="agree" value="true" <?php if ($form['agree']) echo 'checked="checked"' ?> />I agree to the terms of this contest and photo release</label></li></ul> </div> </div> <label id="nothing" value="<?php echo $form['nothing'] ?>">Do not type here <input type="text" name="nothing" /></label> </fieldset> </div><!-- acf-form-fields --> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="Submit" /> <span class="acf-spinner"></span> </div> <!-- / Submit --> </form> </article> <aside id="sidebar"> <div class="sb-item callout_text commercial"> <h3 class="sb-header">About our Calendars</h3> <div class="sb-content commercial"> <?php the_field('entry_sidebar', 'options') ?> </div> </div> </aside> <style> #content-area .field-city { float: left; margin-right: 5%; min-width: 10em; width: 40%; } #content-area .field-state { float: left; margin-right: 5%; min-width: 4em; width: 25%; } #content-area .field-zip { float: left; min-width: 6em; width: 25%; } #content-area .field-photo-title { float: left; margin-right: 5%; min-width: 6em; width: 47.5%; } #content-area .field-photo-loc { float: left; min-width: 6em; width: 47.5%; } fieldset { margin: 1em 0; padding: 0; border: 0; border-top: solid 1px; } legend { font-size: 1.05em; margin: 0.5em 0; line-height: 1.25; color: #1E366D; font-weight: bold; padding-right: 0.5em; } /*-------------------------------------------------------------------------------------------- * * Basic ACF field wrap * *--------------------------------------------------------------------------------------------*/ .acf-field { margin: 0 0 20px; } .acf-field .acf-label { vertical-align: top; margin: 0 0 10px; } .acf-field .acf-label label { display: block; font-weight: bold; font-size: 13px; line-height: 1.4em; margin: 0 0 3px; } .acf-field .acf-label p { color: #777777; display: block; font-size: 12px; line-height: 1.4em; font-style: normal; margin: 3px 0 0 !important; padding: 0 !important; } .acf-field .acf-input { vertical-align: top; } /* field error */ .acf-field .acf-error-message { background: #F55E4F; color: #fff; margin: 0 0 10px; display: inline-block; } .acf-field .acf-error-message:after { content: ""; width: 0; height: 0; border: transparent 5px solid; border-top-color: #F55E4F; display: block; position: absolute; bottom: -10px; left: 10px; } .acf-field .acf-error-message p { margin: 8px 0 !important; } /* add term */ #addtag div.acf-field.error { border: 0 none; padding: 8px 0; } /* widget */ .widget .widget-inside .acf-error-message p { margin: 10px 0; } .widget .widget-inside div.acf-field.error { border: 0 none; background: transparent; margin: 0 0 20px; padding: 0; } /* width */ .acf-field[data-width] { float: left; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .acf-field[data-width] + .acf-field { clear: left; } .acf-field[data-width] + .acf-field[data-width] { clear: none; border-left: 1px solid #eeeeee; } td.acf-field[data-width] { float: none; } /* field width helpers */ .acf-r0 { border-top-width: 0 !important; } .acf-c0 { clear: left !important; border-left-width: 0 !important; } /* rtl */ html[dir="rtl"] .acf-field[data-width] { float: right; } html[dir="rtl"] .acf-field[data-width] + .acf-field { clear: right; } html[dir="rtl"] .acf-field[data-width] + .acf-field[data-width] { clear: none; border-right: 1px solid #eeeeee; } html[dir="rtl"] .acf-c0 { clear: right !important; border-left-width: 1px !important; border-right-width: 0 !important; } /*--------------------------------------------------------------------------------------------- * * Basic Field Styles * *---------------------------------------------------------------------------------------------*/ .acf-field input[type="text"], .acf-field input[type="password"], .acf-field input[type="number"], .acf-field input[type="search"], .acf-field input[type="email"], .acf-field input[type="url"], .acf-field textarea, .acf-field select { width: 100%; padding: 3px 5px; resize: none; margin: 0; box-sizing: border-box; font-size: 14px; line-height: 15px; } .acf-field textarea { resize: vertical; line-height: 1.4em; } /*--------------------------------------------------------------------------------------------- * * Text * *---------------------------------------------------------------------------------------------*/ .acf-input-prepend, .acf-input-append { font-size: 13px; line-height: 19px; height: 20px; padding: 3px 7px; background: #F4F4F4; border: #DFDFDF solid 1px; } .acf-input-prepend { float: left; border-right-width: 0; border-radius: 3px 0 0 3px; } .acf-input-append { float: right; border-left-width: 0; border-radius: 0 3px 3px 0; } .acf-input-wrap { position: relative; overflow: hidden; } .acf-input-wrap input { height: 28px; margin: 0; } input.acf-is-prepended { border-radius: 0 3px 3px 0 !important; } input.acf-is-appended { border-radius: 3px 0 0 3px !important; } input.acf-is-prepended.acf-is-appended { border-radius: 0 !important; } /* rtl */ html[dir="rtl"] .acf-input-prepend { border-left-width: 0; border-right-width: 1px; border-radius: 0 3px 3px 0; float: right; } html[dir="rtl"] .acf-input-append { border-left-width: 1px; border-right-width: 0; border-radius: 3px 0 0 3px; float: left; } html[dir="rtl"] input.acf-is-prepended { border-radius: 3px 0 0 3px !important; } html[dir="rtl"] input.acf-is-appended { border-radius: 0 3px 3px 0 !important; } html[dir="rtl"] input.acf-is-prepended.acf-is-appended { border-radius: 0 !important; } /*--------------------------------------------------------------------------------------------- * * Radio * *---------------------------------------------------------------------------------------------*/ ul.acf-radio-list, ul.acf-checkbox-list { background: transparent !important; position: relative; padding: 1px; margin: 0; } ul.acf-radio-list li, ul.acf-checkbox-list li { font-size: 13px; line-height: 22px; margin: 0; position: relative; word-wrap: break-word; } ul.acf-hl.acf-radio-list li, ul.acf-hl.acf-checkbox-list li { margin-right: 20px; clear: none; } ul.acf-radio-list li input, ul.acf-checkbox-list li input { margin: -1px 4px 0 0; vertical-align: middle; } ul.acf-radio-list li label, ul.acf-checkbox-list li label { display: inline; margin: 2px 0; } ul.acf-radio-list li input[type="text"] { width: auto; } /* rtl */ html[dir="rtl"] ul.acf-radio-list li input, html[dir="rtl"] ul.acf-checkbox-list li input { margin-left: 4px; margin-right: 0; } .acf-field input[type="pattern"], .acf-field input[type="tel"] { box-sizing: border-box; font-size: 14px; line-height: 15px; margin: 0; padding: 3px 5px; resize: none; width: 100%; } #nothing { position: absolute; left: -5000px; top: -5000px; width: 1px; height: 1px; overflow: hidden; color: #00f; background: #fff; padding: 1em; border: solid 1px #000; } .errors { border: solid 1px #D44426; background: #FFF0ED; padding: 1em 1em 1em 2em; border-radius: 0.5em; list-style: square; color: #D44426; margin: 1em 0; } .errors li { margin: 0; padding: 0.5em; text-indent: -0.5em; } code { white-space: pre; } </style> <?php } get_footer();