challenge_results.php
6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* The template for displaying the Challenge Results page .
*
* Template name: Challenge Results
*
* @package storefront
*/
remove_filter('the_content', 'wpautop');
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php
do_action('storefront_page_before');
?>
<?php
?>
<div class="page_challengeresults text-center">
<div class="bg2 text-center">
<div class="container">
<?php
if (isset($_POST['number_cans']) && isset($_POST['amount_pay'])) {
$savings_amount = fgc_calculation_challenge($_POST);
if ($savings_amount > 0) {
?>
<header class="tv-header">
<h1 itemprop="name" class="tv-title">Great news</h1>
</header>
<p class="font20">
If you switch to REIZE Energy Drink you will save
</p>
<h3 class="font30 roboto_condensedbold">
$<?php echo $savings_amount; ?> per year!
</h3>
<p class="font20">
Just think of what you could do with all that cash.
</p>
<?php } else { ?>
<p class="tvnotified">
WHOA… are you claiming that your energy drink is even cheaper than REIZE? We don’t believe it. Has it expired? Is it priced in pesos? Was it given to you by a homeless person?
Whatever it is, there are plenty of other great reasons to drink REIZE. Have a look at the 10 Reasons to Buy REIZE at the bottom of the "Our Drink" page. Or if you made a typo, then take the REIZE Energy Challenge again.
</p>
<?php } ?>
<?php } else { ?>
<p class="tvnotified"><a class="aborder" href="/our-drink">Click here</a> to take the REIZE Energy Drink challenge and find out how much money you could save by switching to REIZE.</p>
<?php } ?>
<div class="form-group"></div>
<img class="inline_block" src="<?php echo get_site_url() . '/wp-content/themes/reize/assets/images/ChallengeResults.png' ?>"/>
<?php if ($savings_amount > 0) { ?>
<div class="tvsocial">
<h2 class="font32 roboto_condensedbold">
invite a friend to take the challenge
</h2>
<?php
echo do_shortcode('[jpshare]');
?>
</div>
<?php } ?>
</div>
</div>
<div class="bg3">
<div class="container">
<div class="font22 text-uppercase footer_page">
<a href="/get-started">
<span class="robotoslab">start saving today.</span> <span class="robotoslabbold"><b>join the club</b></span>
</a>
</div>
</div>
</div>
</div>
<?php
/**
* @hooked storefront_display_comments - 10
*/
do_action('storefront_page_after');
?>
<?php endwhile; // end of the loop. ?>
<?php
$our_link_page = get_page_by_title('OUR DRINK', OBJECT, 'page');
$link_page = get_permalink($our_link_page->ID);
$link_page_replaced = str_replace(array('http://', 'http://wwww.'), array('', ''), $link_page);
?>
<input type="hidden" id="text_twitter" value="Take the REIZE Energy Drink Challenge! <?php echo $link_page_replaced; ?> pic.twitter.com/irO6DrDLOt" />
<input type="hidden" id="text_facebook" value="Take the REIZE Energy Drink Challenge today!" />
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
<?php
/**
* calculate savings amount
* @param type $data
* @return int
*/
function fgc_calculation_challenge($data) {
$yearly_drink = array("144", "360", "720", "1080", "1440", "1800", "2160", "2520", "2880", "3240", "3600", "3960", "4320", "7200");
$Yearly_Subscription_Cost = array("120", "300", "540", "672", "840", "1032", "1200", "1368", "1500", "1656", "1800", "1980", "2100", "3108");
$yearly_arr = array();
for ($i = 0; $i < count($yearly_drink); $i++) {
$yearly_arr[$yearly_drink[$i]] = $Yearly_Subscription_Cost[$i];
}
$number_cans = $data['number_cans'];
$amount_pay = preg_replace("/[^0-9\.]/", '', $data['amount_pay']);
if (is_numeric($number_cans) && is_numeric($amount_pay)) {
$yearly_cost = $number_cans * $amount_pay * 365;
$number_of_energy_drinks = $number_cans * 365;
$closest_plan = fgc_closest($yearly_drink, $number_of_energy_drinks);
$Yearly_Cost_of_Closest_Plan = $yearly_arr[$closest_plan];
$savings_amount = $yearly_cost - $Yearly_Cost_of_Closest_Plan;
//echo $yearly_cost.'--'.$number_of_energy_drinks.'--'.$closest_plan.'--'.$Yearly_Cost_of_Closest_Plan.'--'.$savings_amount;
return number_format($savings_amount);
} else {
return 0;
}
}
function fgc_closest($array, $number) {
sort($array);
$arr = array();
foreach ($array as $a) {
if ($a <= $number) {
$arr[] = $a;
}
}
return max($arr); // or return NULL;
}
?>