-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax.php
More file actions
274 lines (189 loc) · 5.92 KB
/
ajax.php
File metadata and controls
274 lines (189 loc) · 5.92 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
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
<?php
// respond to AJAX calls
include("/share1/proj/eem/templates/functions.php");
// Check Post Input
if (isset($_POST['id'])) {
$id = $_POST['id'];
} else {
die(encodeError("Id not specified."));
}
if (isset($_POST['name'])) {
$name = $_POST['name'];
} else {
die(encodeError("Name not specified."));
}
// Expression Example Upload Handler
if ('expressionExampleUpload'==$name) {
if (isset($_POST['file'])) {
$exampleFile = EXAMPLE_EX_PATH . trim($_POST["file"]);
if (copyUploadedFile($exampleFile, EXPRESSION_ORIGINAL_FILE)) {
die(encodeResult("Uploading Expression successful."));
} else {
die(encodeError("Uploading Expression Example failed, could not move file."));
}
}
die(encodeError("Uploading Expression Example failed."));
}
// Expression Remote Upload Handler
if ('expressionRemoteUpload'==$name) {
if (isset($_POST['file'])) {
$remoteFile = trim($_POST["file"]);
if (copyUploadedFile($remoteFile, EXPRESSION_ORIGINAL_FILE)) {
die(encodeResult("Uploading Remote Expression successful."));
} else {
die(encodeError("Uploading Remote Expression failed, could not move file: ". $remoteFile));
}
}
die(encodeError("Uploading Remote Expression failed."));
}
// Geneset Example Upload Handler
if ('genesetExampleUpload'==$name) {
if (isset($_POST['file'])) {
$exampleFile = EXAMPLE_GENE_PATH . trim($_POST["file"]);
if (copyUploadedFile($exampleFile, GENESET_FILE)) {
die(encodeResult("Uploading Geneset Example successful."));
} else {
die(encodeError("Uploading Geneset Example failed, could not move file: ". $exampleFile));
}
}
die(encodeError("Uploading Geneset Example failed."));
}
// Geneset Remote Upload Handler
if ('genesetRemoteUpload'==$name) {
if (isset($_POST['file'])) {
$remoteFile = trim($_POST["file"]);
if (copyUploadedFile($remoteFile, GENESET_FILE)) {
die(encodeResult("Uploading Remote Geneset successful."));
} else {
die(encodeError("Uploading Remote Geneset failed, could not move file: ". $remoteFile));
}
}
die(encodeError("Uploading Remote Geneset failed."));
}
// Preprocess Example Upload Handler
if ('preprocessExampleUpload'==$name) {
if (isset($_POST['file'])) {
$chipFile = EXAMPLE_PREPROCESS_PATH . trim($_POST["file"]);
if (copyUploadedFile($chipFile, PREPROCESS_FILE)) {
$additionalMessage = "Chip Example File successfully uploaded.";
die(checkFiles($id, $additionalMessage));
} else {
die(encodeError("Uploading Chip Example File failed, could not move file: ". $chipFile));
}
}
die(encodeError("Uploading Chip Example File failed: ". $chipFile ));
}
// Preprocess Remote Upload Handler
if ('preprocessRemoteUpload'==$name) {
if (isset($_POST['file'])) {
$chipFile = trim($_POST["file"]);
if (copyUploadedFile($chipFile, PREPROCESS_FILE)) {
checkFiles($id);
} else {
die(encodeError("Uploading Remote Chip File failed, could not move file: ". $exampleFile));
}
}
die(encodeError("Uploading Remote Chip File failed."));
}
function copyUploadedFile($inputFileName, $fileName) {
global $id;
$dir = DATAPATH . "$id/";
// Create folder, if it does not exist
if (!file_exists($dir))
@mkdir($dir);
$outputPath = $dir . $fileName;
// open & save
if ($data = file_get_contents($inputFileName)) {
if (file_put_contents($outputPath, $data)) {
return true;
}
}
return false;
}
// Check Files
if ('fileCheck'==$name) {
// check files
die(checkFiles($id)); // return reults as JSON
}
// Preprocess Expression File
if ('preProcessExpression'==$name) {
global $id;
$dir = DATAPATH . "$id";
//$type = $_POST['type']; // has to be expression
if (!file_exists("$dir/expression_original.tab")) {
die(encodeError("Preprocessing failed, Expression file does not exist."));
}
// optional chip file
$chip = "";
if( in_array($_POST['type'], array("example", "remote", "local")) ) {
$chipfile = "$dir/preprocess.chip";
if (file_exists($chipfile)) {
$chip = " -c $chipfile";
}
}
// logscale
$logscale = "";
if($_POST['logscale']=="true") {
$logscale = " -l";
}
// variation
$variations = 8000;
if ($_POST['variations'] && is_numeric($_POST['variations'])) {
$variations = $_POST['variations'];
}
// reset preprocess bit
$meta = get_meta();
$meta["preprocess"] = false;
update_meta($meta);
chdir($dir);
$command = "perl /share1/proj/eem/perl/preprocess2.pl$chip expression_original.tab$logscale -v $variations -i $id -o expression.tab";
$ret = null;
$output = array();
exec($command, $output, $ret);
// can't reply on $output and $ret to return success or error of preprocess2.pl...
// in preprocess_finished.php, success bit is write to id folder
// check if $ok or $ng have been written by preprocess_finished.php
$counter = 0;
while(true) {
// check if preprocess is finished
$meta = get_meta();
if ($meta["preprocess"]) break;
if ($counter>30) { // 30 seconds time-out
die(encodeError("Preprocessing timed out."));
}
sleep(1);
$counter++;
}
if ($meta["preprocess"]=="ok") {
die(encodeResult("Preprocessing Successful."));
}
die(encodeError("Preprocessing failed."));
}
// Start Supercomputer
// done via 'normal' form
if ('startSupercomputer'==$name) {
// job gets submitted in status.php (why?)
// Ok
die('{"jsonrpc" : "2.0", "result" : {"message": "Supercomputer started."}, "id" : "'.$id.'"}');
}
// Register Email Supercomputer
if ('registerEmail'==$name) {
global $id;
$email = $_POST['userEmail'];
if (isset($_POST['userEmail'])) {
$meta['email'] = trim($_POST['userEmail']);
update_meta($meta);
die(encodeResult("Email registered: ".$email));
}
die(encodeError("Email registering failed: " . $email));
}
if ('checkIfFinished'==$name) {
global $id;
$meta = get_meta(); // check meta, if its done..
if ($meta['status']==JOB_FINISHED) {
die(encodeResult("Done."));
}
die(encodeError("Not yet finished."));
}
die(encodeError("Could not complete Ajax request."));
?>