-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
223 lines (178 loc) · 6.1 KB
/
index.php
File metadata and controls
223 lines (178 loc) · 6.1 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$pageid = "home";
require_once('include/common.php');
get_document('doctype');
//DYNAMIC <html> tag
get_document('html');
?>
<head>
<?php
echo get_meta('charset'); //UTF-8 CHARSET
echo get_meta('chromeframe'); //FORCES IE TO ACT LIKE CHROME
echo get_meta('viewport'); //MOBILE VIEWPORT
echo get_document('stylesheets'); //EMBED STYLESHEETS
echo get_document('favicon'); //FAVICONS
echo get_document('scripts_header'); //HEADER JAVASCRIPTS
?>
<title>Welcome<?php echo get_meta('title_append'); ?></title>
<meta name="description" content="">
<meta name="author" content="<?php echo get_meta('author'); ?>">
</head>
<body>
<div id="container">
<header>
<h1>Mileage Generator</h1>
</header>
<article id="main">
<?php
if ( isset($_POST['submit']) ):
//FORM HAS BEEN SUBMITTED
extract($_POST);
//Create a new variable to work with
$miles = $startMiles;
//DO SOME MATH
$totalMiles = $endMiles - $startMiles; // 25k - 10k = 15k
echo '<ul>';
echo '<li>Miles: '.$startMiles.' - '.$endMiles.'</li>';
echo '<li>Total Miles Driven: '.$totalMiles.'</li>';
// echo '<li>Average Monthly Miles: '.$monthlyMiles.'</li>';
// echo '<li>Monthly Trips: '.$monthlyTrips.'</li>';
echo '</ul>';
//CREATE A COUNTER
$monthCounter = 1;
//LOOP THROUGH THE MONTHS
while ( $monthCounter <= $months && $miles <= $endMiles ) {
//MAXIMUM NUMBER OF MONTHLY MILES
$monthlyMiles = round($miles / $months);
//CHOOSE AN INTEGER FOR THE MAXIMUM MILES THAT COULD BE DRIVEN IN A MONTH
$monthlyMileMax = round(rand($monthlyMiles - 5,$monthlyMiles));
// FOR EACH MONTH, CHOOSE A RANDOM NUMBER OF TRIPS
$monthlyTrips = round(rand($monthlyTripMin,$monthlyTripMax));
//AVERAGE THE MILES PER TRIP
$avgTripMiles = round($monthlyMileMax / $monthlyTrips);
//CREATE A COUNTER
$tripCounter = 0;
//WHAT IS THE MONTH?
$currentMonth = mktime(0,0,0,$monthStart);
echo '<table width="100%">';
echo '<thead>';
echo '<tr>';
echo '<td>';
echo '<h3>Month of '.date('F, Y',$currentMonth).'</h3>';
echo '</td>';
echo '<td>';
echo 'Maximum miles in this month: '.$monthlyMileMax;
echo '</td>';
echo '<td>';
echo 'Trips made this month: '.$monthlyTrips;
echo '</td>';
echo '<td>';
echo 'Average miles per trip: '.$avgTripMiles;
echo '</td>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
//LOOP THROUGH THE TRIPS
while ( ($tripCounter < $monthlyTrips)) {
//CHOOSE A RANDOM NUMBER OF MILES FOR THE TRIP
$tripMiles = round(rand(5,$avgTripMiles));
echo '<tr>';
echo '<td colspan="4">';
echo '<strong>Trip '.($tripCounter + 1).':</strong> ';
echo $miles.' - '.($miles + $tripMiles);
echo ' ('.$tripMiles.' miles)';
echo '</td>';
echo '</tr>';
//ADD THE MILEAGE TO THE STARTING MILEAGE
$miles = $miles + $tripMiles;
//INCREMENT THE COUNTER
$tripCounter++;
// CREATE A RANDOM NUMBER SO SEQUENCES ARE NON-SEQUENTIAL
// BETWEEN TRIPS
if ( $tripCounter != $monthlyTrips ) {
$miles = $miles + round(rand(0,20));
}
}
echo '</tbody>';
echo '<tfoot>';
echo '<tr>';
echo '<td colspan="4">';
echo '<h5>The odometer currently reads: '.$miles.'</h4>';
echo '</td>';
echo '</tr>';
echo '</tfoot>';
echo '</table>';
//INCREMENT THE MONTHS
$monthCounter++;
$monthStart++;
}
?>
<div class="message warning">
<h5>You drove <?php echo $totalMiles; ?> miles in <?php echo $months; ?> months.</h5>
</div>
<?php
else:
//NO FORM HAS BEEN SUBMITTED
?>
<form action="" method="post" id="input">
<fieldset id="general">
<legend>General settings</legend>
<label for="months">How many months should I generate?</label>
<input type="text" name="months" value="" class="text" />
<div class="inline first">
<label for="monthStart">Begin on month:</label>
<select name="monthStart" id="monthStart">
<option value="1" selected>January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</div>
<div class="inline last">
<label for="yearStart">Begin on year</label>
<select name="yearStart" id="yearStart">
<?php
$now = date('Y');
$yearStart = $now - 5;
while( $yearStart <= $now ) {
if ($yearStart == $now) {
echo '<option selected value="'.$yearStart.'">'.$yearStart.'</option>';
} else {
echo '<option value="'.$yearStart.'">'.$yearStart.'</option>';
}
$yearStart++;
}
?>
</select>
</div>
<label for="startMiles">Starting Mileage</label>
<input type="text" name="startMiles" value="" class="text" />
<label for="endMiles">Ending Mileage</label>
<input type="text" name="endMiles" value="" class="text" />
<label for="monthlyTripMin">How many trips do you make in a month?</label>
<span class="inline first">Between <input type="text" name="monthlyTripMin" value="10" class="small" /></span>
<span class="inline"> trips and <input type="text" name="monthlyTripMax" value="30" class="small" /> trips per month</span>
<input type="submit" name="submit" value="Submit" class="button blue medium" />
</fieldset>
</form>
<?php
endif;
?>
</article>
<footer>
<?php include_once(DOCUMENT_ROOT.'footer.php'); ?>
</footer>
</div> <!-- #container -->
<?php echo get_document('scripts_footer'); ?>
</body>
</html>