|
12 | 12 |
|
13 | 13 | require('../src/Weatherbit.php'); |
14 | 14 |
|
15 | | -$call = isset($_GET['call']) ? $_GET['call'] : ''; |
16 | | -$key = isset($_GET['key']) ? $_GET['key'] : ''; |
17 | | -$city = isset($_GET['city']) ? $_GET['city'] : ''; |
18 | | -$country = isset($_GET['country']) ? $_GET['country'] : ''; |
19 | | -$days = isset($_GET['days']) ? intval($_GET['days']) : 1; |
20 | | -$ip = isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR']; |
| 15 | +$call = isset($_GET['call']) ? $_GET['call'] : ''; |
| 16 | +$key = isset($_GET['key']) ? $_GET['key'] : ''; |
| 17 | +$city = isset($_GET['city']) ? $_GET['city'] : ''; |
| 18 | +$country = isset($_GET['country']) ? $_GET['country'] : ''; |
| 19 | +$days = isset($_GET['days']) ? intval($_GET['days']) : 1; |
| 20 | +$ipAddress = isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR']; |
| 21 | + |
| 22 | +$selected = ' selected="selected"'; |
| 23 | +$callSelected = []; |
| 24 | +$callSelected['forecast'] = ($call == 'forecast') ? $selected : ''; |
| 25 | +$callSelected['current'] = ($call == 'current') ? $selected : ''; |
| 26 | +$callSelected['usage'] = ($call == 'usage') ? $selected : ''; |
21 | 27 |
|
22 | 28 | $pageTitle= 'Weatherbit v' . Weatherbit::VERSION . ' web test'; |
23 | 29 |
|
24 | | -?> |
25 | | -<html> |
| 30 | +print '<html> |
26 | 31 | <head> |
27 | | - <title><?= $pageTitle ?></title> |
| 32 | + <title>' . $pageTitle . '</title> |
28 | 33 | </head> |
29 | 34 | <body> |
30 | | - <h1><?= $pageTitle ?></h1> |
| 35 | + <h1>' . $pageTitle . '</h1> |
31 | 36 | <form> |
32 | 37 | Call: <select name="call"> |
33 | | - <option value="forecast"<?= $call == 'forecast' ? ' selected="selected"' : '' ?>>Daily Weather Forecast</option> |
34 | | - <option value="current"<?= $call == 'current' ? ' selected="selected"' : '' ?>>Current Weather</option> |
35 | | - <option value="usage"<?= $call == 'usage' ? ' selected="selected"' : '' ?>>API Usage</option> |
| 38 | + <option value="forecast"' . $callSelected['forecast'] . '>Daily Weather Forecast</option> |
| 39 | + <option value="current"' . $callSelected['current'] . '>Current Weather</option> |
| 40 | + <option value="usage"' . $callSelected['usage'] . '>API Usage</option> |
36 | 41 | </select><br /><br /> |
37 | | - API Key: <input name="key" type="text" value="<?= htmlentities($key) ?>" size="35" /><br /><br /> |
38 | | - City: <input name="city" type="text" value="<?= htmlentities($city) ?>" size="20" /><br /><br /> |
39 | | - Country: <input name="country" type="text" value="<?= htmlentities($country) ?>" size="2" maxlength="2" /> |
| 42 | + API Key: <input name="key" type="text" value="' . htmlentities($key) . '" size="35" /><br /><br /> |
| 43 | + City: <input name="city" type="text" value="' . htmlentities($city) . '" size="20" /><br /><br /> |
| 44 | + Country: <input name="country" type="text" value="' . htmlentities($country) . '" size="2" maxlength="2" /> |
40 | 45 | (2 Letter Country Code)<br /><br /> |
41 | | - Forecast Days (1-16): <input name="days" type="text" value="<?= $days ?>" size="2" maxlength="2" /><br /><br /> |
42 | | - IP: <input name="ip" type="text" value="<?= $ip ?>" size="20" /> |
| 46 | + Forecast Days (1-16): <input name="days" type="text" value="' . $days . '" size="2" maxlength="2" /><br /><br /> |
| 47 | + IP Address: <input name="ip" type="text" value="' . $ipAddress . '" size="20" /> |
43 | 48 | <br /><br /> |
44 | 49 | <input type="hidden" name="run" value="test" /> |
45 | 50 | <input type="submit" value=" Get Weatherbit API Response " /> |
46 | | - <a href="<?= $_SERVER['PHP_SELF'] ?>">reset</a> |
47 | | - </form> |
48 | | -<?php |
| 51 | + <a href="' . $_SERVER['PHP_SELF'] . '">reset</a> |
| 52 | + </form>'; |
49 | 53 |
|
50 | 54 | if (!isset($_GET['run']) || $_GET['run'] != 'test') { |
51 | 55 | testFooter(); |
|
73 | 77 | $data = $weatherbit->getUsage(); |
74 | 78 | break; |
75 | 79 | default: |
76 | | - throw new Exception('Invalid Call type'); |
| 80 | + $error = 'Invalid Call type'; |
| 81 | + break; |
77 | 82 | } |
78 | 83 | } catch (Exception $error) { |
79 | 84 | $error = $error->getMessage(); |
|
0 commit comments