-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.php
111 lines (76 loc) · 3.21 KB
/
result.php
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
<!DOCTYPE html>
<?php
if (!isset($_POST["color"])) {
echo "<script>window.location.href = 'view_result.php';</script>";
exit();
}
$file = fopen("data.txt", "a") or die("Unable to open file!");
$txt = $_POST["color"].$_POST["red"].$_POST["green"].$_POST["blue"]."\n";
fwrite($file, $txt);
fclose($file);
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Your Choices - Colors</title>
<link rel="Shortcut Icon" href="favicon.ico">
<!-- jquery -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<!-- bootstrap v5.0 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- custom styles -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<img src="img/2.png" alt="colors" style="display:none;">
<p>Your choices:</p>
<ball style="background: <?php echo $_POST["color"]; ?>"></ball>
<ball style="background: <?php echo $_POST["red"]; ?>"></ball>
<ball style="background: <?php echo $_POST["green"]; ?>"></ball>
<ball style="background: <?php echo $_POST["blue"]; ?>"></ball>
<?php
include_once("codes/hex.php");
// READ FILE STARTS HERE
$file = fopen("data.txt","r");
$data = fgets($file);
$count = 1;
$color = data2array($data, 0);
$red = data2array($data, 1);
$green = data2array($data, 2);
$blue = data2array($data, 3);
while(! feof($file)) {
$data = fgets($file);
if (empty($data)) { break; } // Break out at the last empty line
$count += 1;
$color = arrays_sum($color, data2array($data, 0));
$red = arrays_sum($red , data2array($data, 1));
$green = arrays_sum($green, data2array($data, 2));
$blue = arrays_sum($blue , data2array($data, 3));
}
fclose($file);
$color = arrays_average($color, $count);
$red = arrays_average($red , $count);
$green = arrays_average($green, $count);
$blue = arrays_average($blue , $count);
$color = array2hex($color);
$red = array2hex($red );
$green = array2hex($green);
$blue = array2hex($blue );
?>
<p>Colors by <?=$count?> people:</p>
<ball style="background: <?=$color?>"></ball>
<ball style="background: <?=$red ?>"></ball>
<ball style="background: <?=$green?>"></ball>
<ball style="background: <?=$blue ?>"></ball>
<p>
<button type="button" class="btn btn-secondary" onclick="window.location.href = 'view_result.php';">Result Page</button>
</p>
<!-- tooltips -->
<script src="codes/color-tooltips.js" charset="utf-8"></script>
<!-- custom code -->
<script src="codes/github-link.js" charset="utf-8"></script>
</body>
</html>