-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
116 lines (105 loc) · 3.63 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
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
<?php
session_start();
require_once("DFA.php");
if (isset($_POST['submit'])) {
$_SESSION['states'] = file_get_contents($_FILES['inputFile']['tmp_name']);
$objDFA = new DFA;
$objDFA->getFromFile($_FILES['inputFile']['tmp_name']);
//echo $objDFA->getStateSequence("011");
//$objDFA->displayTransition();
//echo '<br />';
/*
if ($objDFA->isAccepted("011"))
echo "ACCEPTED";
else
echo "REJECTED";
*/
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css" />
<title>DFA Simulator</title>
</head>
<body>
<div class="container">
<form method="post" enctype="multipart/form-data">
<h2>DFA Simulator</h2>
<label for="inputFile">Load transition table from file: </label>
<input name="inputFile" type="file" id="fileTrans" class="form-control" placeholder="Upload File" required autofocus>
<button class="btn btn-md btn-primary btn-block" id="btnLoadFile" name="submit" type="submit">Load File</button>
</form>
<div class="alert alert-info" id="fName"></div>
<table class="table table-sm table-nonfluid center-table table-bordered">
<thead class="thead-inverse">
<tr>
<th>State</th>
<th>0</th>
<th>1</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['submit'])) {
echo $objDFA->transitionToTr();
}
?>
</tbody>
</table>
<form id="formInputString">
<div class="input-group">
<span class="input-group-addon" id="basic-addon3">Input string</span>
<input type="text" class="form-control" id="inputString" aria-describedby="basic-addon3" />
</div>
<div class="alert alert-info" id="outputDFA">
Type the input string on the textbox above
</div>
</form>
</div>
<script src="libs/jquery-3.1.0.min.js"></script>
<script src="libs/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>
$(function(){
<?php
if (isset($_POST['submit'])) {
echo '$("table").show();' . "\n";
echo '$("#fName").html("File <strong>' . $_FILES['inputFile']['name'] . '</strong> successfully loaded with the following data");' . "\n";
echo '$("#fName").show();' . "\n";
echo '$("#formInputString").show();' . "\n";
echo '$("#outputDFA").show();' . "\n";
} else {
echo '$("table").hide();' . "\n";
echo '$("#fName").hide();' . "\n";
echo '$("#formInputString").hide();' . "\n";
echo '$("#outputDFA").hide();' . "\n";
}
?>
$('#inputString').on('input', function() {
$(this).val($(this).val().replace(/[^0-1]/g,''));
$.ajax({
type : 'get',
url : 'act_ajax.php',
data : 'input=' + $('#inputString').val(),
dataType : 'json',
success : function(response) {
var output = $('#outputDFA');
output.html("<strong>" + response['output'] + "</strong>");
output.show();
$('tr').removeClass('cur_state');
$('#s' + response['cur_state']).addClass('cur_state');
if ($('#inputString').val().length == 0)
output.html('Type the input string on the textbox above');
else {
var sequence = "<br />Sequences: " + response['sequence'];
output.append(sequence);
}
}
});
});
});
</script>
</body>
</html>