/
calc.php
299 lines (262 loc) · 6.82 KB
/
calc.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
// CODE FOR SESSION CHECK
//start session
session_start();
//if username is not set, send to login page.
if (!(isset($_SESSION["user"]))) {
header('Location: ./Signup.php');
}
printTop();
printForm();
//Add logic for printing out calculated results
$box = False;
$sho = False;
$pos = False;
$gse = False;
$elev = False;
$flag1 = False;
$flag2 = False;
if (isset($_POST['method']) and $_POST['method'] != "") {
$flag1 = True;
$method = $_POST['method'];
foreach ($method as $m){
if ($m == "PIB") $box = True;
elseif ($m == "SHO") $sho = True;
elseif ($m == "POS") $pos = True;
}
}
if (isset($_POST["calc"]) and $_POST["calc"] != "") {
$flag2 = True;
$calc = $_POST['calc'];
foreach ($calc as $value){
if ($value == "GSE") $gse = True;
elseif ($value == "energy") $elev = True;
}
}
if ($flag1 && $flag2) printResults($_POST["atom"], $box, $sho, $pos, $gse, $elev);
printBottom();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~BEGIN FUNCTIONS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Need to add javascript in printBottom() to check for correct submission?
function printForm(){
$script = $_SERVER['PHP_SELF'];
//Maybe put a box around the form so it looks cool?
print<<<FORM
<div id="content">
<div id="c2">
<p><b> Select your Parameters </b></p>
<form method="POST" action=$script id="formContent">
<p> Atom: <select name="atom">
<option selected="selected"> H </option>
<option> He </option>
<option> Li </option>
<option> Be </option>
<option> B </option>
<option> C </option>
<option> O </option>
<option> N </option>
<option> F </option>
<option> Ne </option>
</select>
</p>
<p> Method: <input name="method[]" type="checkbox" value="PIB"/> P.I.B
<input name="method[]" type="checkbox" value="POS"/> P.O.S </lable>
<p> Calculation: <input name="calc[]" type="checkbox" value="GSE"/> <label>Ground State Energy </lable>
<input name="calc[]" type="checkbox" value="energy" /> <label> Energy Levels </label></p>
<pre><input type="submit" size="30" value="Submit"/> <input type="reset" size="30" value="Clear"/> </pre>
</form>
</div>
</div>
FORM;
}
function printResults($atom, $box, $sho, $pos, $gse, $elev){
print<<<RESTOP
<div id="content">
RESTOP;
//get password from file
$file = fopen("/u/james/dbase.txt","r");
$line = fgets($file);
$line = trim($line);
fclose ($file);
//Connect to MySQL database
$host = "fall-2015.cs.utexas.edu";
$user = "james";
$pwd = $line;
$dbs = "cs329e_james";
$port = "3306";
$connect = mysqli_connect ($host, $user, $pwd, $dbs, $port);
if (empty($connect))
{
die("mysqli_connect failed: " . mysqli_connect_error());
}
$table = "calc";
$result = mysqli_query($connect, "SELECT * from $table WHERE atom = '$atom'");
while ($row = $result->fetch_row()) {
$element = $row[0];
$numE = $row[1];
$radius =$row[2];
$length =floatval(2*$row[2]);
$mass = floatval($row[3]);
}
$result->free();
mysqli_close($connect);
//Logic for each print...
//Particle in a box energies
if ($box) {
$boxE1 = pow(3.14159, 2)/(2*$length);
$boxE2 = (pow(3.14159, 2)*4)/(2*$length);
$boxE3 = (pow(3.14159, 2)*9)/(2*$length);
//Print results
if ($gse){
print<<<GSEBOX
<div id="c1">
<p> <b> Ground State Energy - Particle in a 1-D box </b>
<table border="1px solid black;">
<thead>
<td><b> Calculation</b> </td><td><b>Energy (hartrees)</b></td>
</thead>
<tbody>
<tr>
<td> Atom </td><td>$element</td>
</tr>
<tr>
<td> Ground State Energy </td><td>$boxE1</td>
</tr>
</tbody>
</table>
</p>
</div>
GSEBOX;
}
if ($elev){
print<<<elevBOX
<div id="c1">
<p> <b>Energy Levels - Particle in a 1-D Box</b>
<table border="1px solid black;">
<thead>
<td><b> Calculation</b> </td><td><b>Energy (hartrees)</b></td>
</thead>
<tbody>
<tr>
<td> Atom </td><td>$element</td>
</tr>
<tr>
<td> 1st Energy Level </td><td>$boxE1</td>
</tr>
<tr>
<td> 2nd Energy Level </td><td>$boxE2</td>
</tr>
<tr>
<td> 3rd Energy Level </td><td>$boxE3</td>
</tr>
</tbody>
</table>
</p>
</div>
elevBOX;
}
}
//Particle on a sphere energies
if ($pos) {
$posE1 = 0;
$posE2 = 1/pow($radius, 2);
$posE3 = 6/(2*pow($radius, 2));
if ($gse){
print<<<GSEPOS
<div id="c1">
<p> <b> Ground State Energy - Particle on a Sphere </b>
<table border="1px solid black;">
<thead>
<td><b> Calculation</b> </td><td><b>Energy (hartrees)</b></td>
</thead>
<tbody>
<tr>
<td> Atom </td><td>$element</td>
</tr>
<tr>
<td> Ground State Energy </td><td>$posE1</td>
</tr>
</tbody>
</table>
</p>
</div>
GSEPOS;
}
if ($elev){
print<<<elevPOS
<div id="c1">
<p> <b>Energy Levels - Particle on a Sphere</b>
<table border="1px solid black;">
<thead>
<td><b> Calculation</b> </td><td><b>Energy (hartrees)</b></td>
</thead>
<tbody>
<tr>
<td> Atom </td><td>$element</td>
</tr>
<tr>
<td> 1st Energy Level </td><td>$posE1</td>
</tr>
<tr>
<td> 2nd Energy Level </td><td>$posE2</td>
</tr>
<tr>
<td> 3rd Energy Level </td><td>$posE3</td>
</tr>
</tbody>
</table>
</p>
</div>
elevPOS;
}
}
//CLOSE OUT DIVS
print<<<RESEND
</div>
RESEND;
}
function printTop() {
//Print the top of the page.
print<<<TOP
<html>
<head>
<meta charset = "utf-8" />
<title> Quantum Calculator </title>
<link rel = "stylesheet" type = "text/css" href = "./calc.css" media = "all" />
</head>
<body>
<!-- This is the top of the page -->
<div id="container">
<div id="top">
<a id="logo1" href = "./Home.php">
<img src = "./logo.jpg" alt = "Logo" width="100" height="100" />
</a>
<a id="logo2" href = "./Home.php">
<img src = "./logo.jpg" alt = "Logo" width="100" height="100" />
</a>
<div id="title"> QUANTUM CALCULATOR </div>
<div id="navBar">
<table id="toptable">
<tr>
<td id="toptd" class="tab" ><a class="btton" id="button1" href = "./Home.php"> HOME</a></td>
<td id="toptd" class="tab" ><a class="btton" id="button2" href = "./Background.php"> BACKGROUND</a></td>
<td id="toptd" class="tab" ><a class="btton" id="button3" href = "./calc.php"> CALCULATOR</a></td>
<td id="toptd" class="tab" ><a class="btton" id="button4" href = "./ContactUs.php"> CONTACT US</a></td>
<td id="toptd" class="tab" ><a class="btton" id="button5" href = "./Logout.php"> LOGOUT </a> </td>
</tr>
</tbody>
</table>
</div>
</div>
TOP;
}
function printBottom() {
//Footer and close of html tags
print<<<BOTTOM
<div id="footer">
<i>Copyright © 2015 Quantum Calculator</i>
</div>
</body>
</html>
BOTTOM;
}
?>