Skip to content

Instantly share code, notes, and snippets.

@jjjjcccjjf
Created December 18, 2017 07:53
Show Gist options
  • Save jjjjcccjjf/80ed99e7fdd7e8f1eb914ff9ca2af505 to your computer and use it in GitHub Desktop.
Save jjjjcccjjf/80ed99e7fdd7e8f1eb914ff9ca2af505 to your computer and use it in GitHub Desktop.
<?php
/* Template Name: Inquire now */
get_header();
# Block for brand & project name
$page_id = 884; # Page ID: Welcome - Ayala Group Employee
if(isset($_SESSION['employer_type']) && $_SESSION['employer_type'] == "Corporate partners")
{
$page_id = 885; # Page ID: Welcome - Corporate partners
}
$employers = get_field("employers_list", $page_id);
$projects_query = new WP_Query(array("post_type" => "project", "posts_per_page" => "-1", 'order' => 'asc', 'orderby' => 'post_title'));
$projects = array();
if ( $projects_query->have_posts() ) { while ( $projects_query->have_posts() ): $projects_query->the_post();
$title = get_the_title();
$brand = str_replace(" ", "_", get_field("brand"));
$projects[$title] = $brand;
endwhile; wp_reset_postdata(); }
# / Block for brand & project name
# Check number of family mart winners
global $wpdb;
$fm_count = $wpdb->get_var("SELECT COUNT(fp.id) as `total` FROM `fm_promo` fp LEFT JOIN `emails_acentives_discount` ead ON fp.emails_id = ead.id WHERE ead.date_sent >= '2017-11-22 00:00:00'");
date_default_timezone_set("Asia/Manila");
$fm_date = date("Y-m-d H:i:s");
$fm_cond = false;
if($fm_count < 500 && $fm_date < date("Y-m-d H:i:s", strtotime("2017-12-15 23:59:59")) && $fm_date >= date("Y-m-d H:i:s", strtotime("2017-11-22 00:00:00")))
{
$fm_cond = true;
}
if($fm_cond)
{
$fm_list = $wpdb->get_results("SELECT * FROM fm_list WHERE 1 ORDER BY area, store ASC");
}
while(have_posts()): the_post();
?>
<section class="projects">
<article class="forms">
<h3 style="color:#000">Inquire Now</h3>
<aside class="tab">
<ul>
<!-- <li class="current"><a href="<?php #echo get_permalink(925); ?>">Am I qualified for Acentives Discount?</a></li> -->
<!-- <li><a href="<?php #echo get_permalink(943); ?>">Send Inquiry</a></li> -->
</ul>
</aside>
<form method="post" id="_form">
<div class="forms-main">
<p>Get in touch with us. Please fill up the form to submit your inquiry.</p>
<ul>
<?php if($_SESSION['employer_type'] != "BANK/INSTITUTIONAL OFFERS"): ?>
<li>
<label>Your Employer</label>
<select name="employer">
<?php
if($_SESSION['employer_type'] == 'Ayala Group Employee'){
$employers = get_field("employers_list", 884);
}else if($_SESSION['employer_type'] == 'Corporate partners'){
$employers = get_field("employers_list", 885);
}else{
$employers = array_merge(get_field("employers_list", 884), get_field("employers_list", 885));
}
$emp_formatted = [];
foreach ($employers as $emp) {
$emp_formatted[] = $emp['employee_name'];
}
sort($emp_formatted);
foreach ($emp_formatted as $emp) { ?>
<option <?php echo ($emp == $_SESSION['employer_name']) ? 'selected' :'' ; ?>>
<?php echo $emp ?></option>
<?php
}
?>
</select>
</li>
<?php endif; ?>
<li>
<label>Your Name</label>
<input type="text" name="name" required>
</li>
<li>
<label>Your Email</label>
<input type="email" name="email" required>
</li>
<li>
<label>Contact Number</label>
<input type="text" name="contact_num" required>
</li>
<?php if($_SESSION['employer_type'] != "BANK/INSTITUTIONAL OFFERS"): ?>
<li>
<label>Years of Service</label>
<select name="service_years" required>
<option disabled >Select years of service</option>
<option>1 - 2 years</option>
<option>3 - 4 years</option>
<option>5 - 6 years</option>
</select>
</li>
<?php endif; ?>
<li>
<label>Brand</label>
<select name="brand" onchange="set_projects($(this).val());" required>
<option value="" >Select Brand</option>
<?php
$field_key = "field_59914863f7455"; # Find this in ACF itself under `Screen Options`, "Projects field Group"
$field = get_field_object($field_key);
if($field){
foreach( $field['choices'] as $choice ) { ?>
<option <?php echo isset($_GET['b']) && $_GET['b'] == $choice ? "selected" : ""; ?>><?php echo $choice; ?></option>
<?php
}
}
?>
</select>
<select name="project_name" id="project_name" required>
<option>Select Project</option>
<?php foreach ($projects as $title => $brand) { ?>
<option class="option_project <?php echo $brand ?>" value="<?php echo $title; ?>"><?php echo $title; ?></option>
<?php } ?>
</select>
</li>
<li>
<label>Your Message</label>
<textarea name="message" required></textarea>
</li>
<!-- <li>
<label class="hide">&nbsp;</label>
<ul>
<li><label><input type="radio" name="employee_type" value="Regular Employee">Regular Employee</label></li>
<li><label><input type="radio" name="employee_type" value="Contractual Employee">Contractual Employee</label></li>
</ul>
</li> -->
<li>
<p style="width:100%;">
<input type="checkbox" value="1" id="agree_terms"> I agree to the
<a href="<?php echo get_permalink(917) ?>" class="linkstyle">Privacy Policy</a> and <a href="<?php echo get_permalink(907) ?>" class="linkstyle">Terms and Conditions</a>
</p>
</li>
<li>
<div class="g-recaptcha" id="recaptcha"></div>
</li>
<?php if($fm_cond): ?>
<li>
<div>
Be among the first 500 employees to claim for free Cornetto Ice Cream from Family Mart.
Please choose your preferred Family Mart branch to redeem your free ice cream.
</div>
</li>
<li>
<select name="fm_id" id="fm_id" required>
<option value="">Select Family Mart Store</option>
<?php foreach ($fm_list as $list) { ?>
<option value="<?php echo $list->id ?>"><?php echo ucwords($list->area)."&nbsp;&nbsp;|&nbsp;&nbsp;".ucwords(strtolower($list->store)); ?></option>
<?php } ?>
</select>
</li>
<?php endif; ?>
<li>
<input type="submit">
</li>
</form>
</ul>
</div>
</article>
<div class="other-links">
<?php displaySideNav($_SESSION['employer_type']); # Find this in header.php ?>
</div>
</section>
<?php
endwhile;
get_footer();
?>
<script>
$(document).ready(function() {
$("#_form").on('submit', function(e){
e.preventDefault();
if($('#agree_terms:checked').length > 0 && grecaptcha.getResponse() != ""){
// console.log(grecaptcha.getResponse());
$.ajax({
url:"<?php echo get_template_directory_uri(); ?>/ajax/acentives_discount_inquiry.php",
type: "POST",
data: $(this).serialize(),
success:function(data){
console.log(data);
if(data == 1){
window.location.href = '<?php echo get_permalink(1141); ?>?type=acentives_discount_inquiry';
}
if(data == 2){
window.location.href = '<?php echo get_permalink(1141); ?>?type=acentives_discount_inquiry&pr=1';
}
}, // success end
error: function(e){
console.log(e);
}
}); // ajax end
}else{
alert('You must agree to the privacy policy and terms and conditions and pass recaptcha to proceed.');
}
});
});
function set_projects(brand)
{
if(brand != "")
{
brand = brand.replace(" ", "_");
$('#project_name').val("");
$(".option_project").attr("style", "display:none");
$("."+brand).attr("style", "display:block");
}
else
{
$('#project_name').val("");
$(".option_project").attr("style", "display:block");
}
}
$(document).ready(function() {
set_projects('<?php echo @$_GET['b'] ?>');
setTimeout(function () {
$("select[name=project_name] option[value='"+ '<?php echo @$_GET['t']; ?>' +"']").prop('selected', true);
}, 100);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment