-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
78 lines (65 loc) · 1.71 KB
/
index.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
<?php
$sampleText = '';
$output = '';
if (isset($_REQUEST['sampleText'])) {
$sampleText = stripslashes($_REQUEST['sampleText']);
if (strlen($sampleText) == 0) {
$sampleSubmittedText = '<p id="sampleSubmittedText" style="color: red">Sample cannot be blank!</p>';
} else {
$sampleSubmittedText = '<p id="sampleSubmittedText" style="color: green">Text sample submitted</p>';
$fileName = 'sample.txt';
$filePath = dirname(__FILE__) . "/sample-text/$fileName";
if (!file_put_contents($filePath, $sampleText)) {
$sampleSubmittedText = '<p id="sampleSubmittedText" style="color: red;">Error copying text to file!</p>';
} else {
$cmd = "./productive_vocab.rb $filePath";
$output = shell_exec($cmd);
}
}
} else {
$sampleSubmittedText = '<p id="sampleSubmittedText"/>';
}
if (strlen($output) != 0) {
$outputDiv = "<h3>Results:</h3><div id=\"resultsDiv\"><pre>$output</pre></div>";
} else {
$outputDiv = '';
}
$html = "
<html>
<head>
<style type=\"text/css\">
body {
background-color: silver;
}
#sampleText {
width: 800px;
height: 400px;
}
#sampleSubmittedText {
height: 14px;
}
#resultsDiv {
background-color: white;
/*padding-left: 40px;*/
border: 1px solid black;
width: 400px;
}
</style>
</head>
<body>
<center>
<h1>Welcome to the Productive Vocabulary Test!</h1>
$sampleSubmittedText
<h3>Enter sample text below</h3>
<form action=\"\" method=\"POST\">
<textarea id=\"sampleText\" name=\"sampleText\">$sampleText</textarea>
<br/>
<input type=\"submit\" value=\"Submit\"/>
</form>
$outputDiv
</center>
</body>
</html>
";
echo $html;
?>