-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrscript.php
More file actions
163 lines (151 loc) · 7.1 KB
/
rscript.php
File metadata and controls
163 lines (151 loc) · 7.1 KB
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
<?php
include_once 'connection/checkUser.php';
include_once 'parts/header.php';
$err = '';
$success = '';
$result = '';
//check if postback
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if($_POST['algorithm'] == "new") {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if file already exists
/*if (file_exists($target_file)) {
$err = "Sorry, file already exists.";
$uploadOk = 0;
}*/
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
$err = "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ($fileType != "R") {
$err = "Sorry, only R files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$err = "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$success = "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded successfully";
} else {
$err = "Sorry, there was an error uploading your file.";
}
}
}
else if($_POST['algorithm'] == "sofa") {
// run sofa algorithm
$_FILES["fileToUpload"]["name"] = "C:/wamp/www/ADSS-Prototype/uploads/printx.R";
} else if($_POST['algorithm'] == "morbidity") {
// run morbidity
$err = "Morbidity not yet implemented";
}
}
if (($_SERVER["REQUEST_METHOD"] == "POST") && empty($err)) {
chdir("C:/Program Files/R/R-3.2.3/bin/i386");
$result = shell_exec("Rscript C:/wamp/www/ADSS-Prototype/uploads/".$_FILES["fileToUpload"]["name"]);
debug($result);
//$result = explode(" ", $result)[1];
//if(empty($result))
//{
//$result = "<embed width='100%' height='100%' src='http://localhost/ADSS-Prototype/uploads/Rplots.pdf' type='application/pdf'></embed>";
//}
}
?>
<body>
<div id="wrapper">
<?php include_once 'parts/nav.php'; ?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Run Algorithms</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<legend>Upload R File:</legend>
<?php if (!empty($err)) { ?>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign"
aria-hidden="true"></span>
<?php echo $err ?>
</div>
<?php } ?>
<?php if (!empty($success)) { ?>
<div class="alert alert-success" role="alert">
<span class="glyphicon glyphicon-exclamation-sign"
aria-hidden="true"></span>
<?php echo $success ?>
</div>
<?php } ?>
<form role="form" method="POST" enctype="multipart/form-data" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>>
<div class="form-group">
<select id="algorithm" name="algorithm" class="form-control">
<option value="sofa">SOFA</option>
<option value="morbidity">Morbidity</option>
<option value="new">New</option>
</select>
<div id="new_algo" style="display: none;">
<p></p>
<select id="algo_type" name="algo_type" class="form-control">
<option>Retro</option>
<option>Pre</option>
</select>
<p></p>
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
</div>
<?php if (!empty($result)) { ?>
<div class="panel panel-primary">
<div class="panel-heading">
Result
</div>
<div class="panel-body">
<?php echo $result ?>
</div>
</div>
<?php } ?>
<p></p>
<input type="submit" class="btn btn-success" value="Submit" name="submit">
</form>
</div>
</div>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<script type="text/javascript">
window.onload = function() {
var eSelect = document.getElementById('algorithm');
var totalAlgorithms = eSelect.options.length-1;
var optOtherReason = document.getElementById('new_algo');
eSelect.onchange = function() {
if(eSelect.selectedIndex === totalAlgorithms) {
optOtherReason.style.display = 'block';
} else {
optOtherReason.style.display = 'none';
}
}
}
</script>
<?php
include_once 'parts/bottom.php';
// }
?>
</body>
</html>