-
Notifications
You must be signed in to change notification settings - Fork 9
/
create_job.php
501 lines (410 loc) · 16.7 KB
/
create_job.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<?php
// This file is part of the Huygens Remote Manager
// Copyright and license notice: see license.txt
// Do not time out this page
set_time_limit(0);
use hrm\Fileserver;
use hrm\job\JobDescription;
use hrm\Nav;
use hrm\param\NumberOfChannels;
use hrm\param\OutputFileFormat;
use hrm\param\TimeInterval;
use hrm\System;
use hrm\Util;
require_once dirname(__FILE__) . '/inc/bootstrap.php';
session_start();
if (isset($_GET['home'])) {
header("Location: " . "home.php");
exit();
}
if (!isset($_SESSION['user']) || !$_SESSION['user']->isLoggedIn()) {
header("Location: " . "login.php");
exit();
}
if (!isset($_SESSION['fileserver'])) {
$name = $_SESSION['user']->name();
$_SESSION['fileserver'] = new Fileserver($name);
}
if (System::hasLicense("coloc")) {
$currentStep = 5;
$goBackLink = "select_analysis_settings.php";
$goBackMessage = "Analysis parameters.";
} else {
$currentStep = 4;
$goBackLink = "select_task_settings.php";
$goBackMessage = "Processing parameters.";
}
$previousStep = $currentStep - 1;
$goBackMessage = "Go back to step $previousStep/$currentStep - " . $goBackMessage;
$message = "";
if (isset($_POST['create'])) {
/** @var OutputFileFormat $parameter */
$parameter = $_SESSION['task_setting']->parameter("OutputFileFormat");
$parameter->setValue($_POST['OutputFileFormat']);
$_SESSION['task_setting']->set($parameter);
// save preferred output file format
if ($_SESSION['task_setting']->save()) {
// TODO source/destination folder names should be given to JobDescription
// Call to sanitize files this will replace special characters with
// underscores. A warning is shown in the case this would actually
// change any file names.
$_SESSION['fileserver']->sanitizeFiles();
$job = new JobDescription();
$job->setParameterSetting($_SESSION['setting']);
$job->setTaskSetting($_SESSION['task_setting']);
$job->setAnalysisSetting($_SESSION['analysis_setting']);
$job->setFiles($_SESSION['fileserver']->selectedFiles(), $_SESSION['autoseries']);
if ($job->addJob()) {
$_SESSION['jobcreated'] = true;
$_SESSION['numberjobadded'] = count($job->files());
header("Location: " . "home.php");
exit();
} else {
$message = $job->message();
}
} else {
$message = "An unknown error has occurred. " .
"Please inform the administrator";
}
} elseif (isset($_POST['OK'])) {
header("Location: " . "select_parameter_settings.php");
exit();
}
include("header.inc.php");
?>
<!--
Tooltips
-->
<span class="toolTip" id="ttSpanBack">
<?php echo $goBackMessage; ?>
</span>
<span class="toolTip" id="ttSpanCreateJob">
Create job, add it to the queue, and go back to your home page.
</span>
<div id="nav">
<div id="navleft">
<ul>
<?php
echo(Nav::linkWikiPage('HuygensRemoteManagerHelpCreateJob'));
?>
</ul>
</div>
<div id="navright">
<ul>
<?php
echo(Nav::textUser($_SESSION['user']->name()));
if (!$_SESSION['user']->isAdmin()) {
echo(Nav::linkRawImages());
}
echo(Nav::linkJobQueue());
echo(Nav::linkHome(Util::getThisPageName()));
?>
</ul>
</div>
<div class="clear"></div>
</div>
<div id="content">
<h3><img alt="Launch" src="./images/launch.png" width="40"/>
Step
<?php echo $currentStep . "/" . $currentStep; ?>
- Launch the job</h3>
<form method="post" action="" id="createjob">
<fieldset class="setting">
<legend>
<a href="javascript:openWindow(
'http://www.svi.nl/FileFormats')">
<img src="images/help.png" alt="?"/>
</a>
Output file format
</legend>
<?php
/** @var OutputFileFormat $parameter */
$parameter = $_SESSION['task_setting']->parameter("OutputFileFormat");
$value = $parameter->value();
/** @var TimeInterval $timeParameter */
$timeParameter = $_SESSION['setting']->parameter("TimeInterval");
$timeValue = $timeParameter->value();
// Make sure that if we had TIFF (8 or 16 bit) as output file format and a
// multichannel dataset, we reset the value to ics2
if (($value == 'TIFF 8-bit') || ($value == 'TIFF 16-bit')) {
/** @var NumberOfChannels $nChannelsParameter */
$nChannelsParameter = $_SESSION['setting']->parameter("NumberOfChannels");
$numberOfChannels = $nChannelsParameter->value();
if ($numberOfChannels > 1) {
$parameter->setValue("ICS2 (Image Cytometry Standard 2)");
$_SESSION['first_visit'] = false;
}
}
// Make sure that if we had RGB-TIFF 8 bit as output file format and a
// single-channel dataset or more than 3 channels, we reset the value to ics2
if ($value == 'RGB TIFF 8-bit') {
$nChannelsParameter = $_SESSION['setting']->parameter("NumberOfChannels");
$numberOfChannels = $nChannelsParameter->value();
if (($numberOfChannels == 1 || $numberOfChannels > 3)) {
$parameter->setValue("ICS2 (Image Cytometry Standard 2)");
$_SESSION['first_visit'] = false;
}
}
// Make sure that if we had TIFF 8 or TIFF 16 as output file format
// and a time-series dataset, we reset the value to ics2
if (
($value == 'TIFF 8-bit') || ($value == 'TIFF 16-bit')
) {
if (($_SESSION['autoseries'] == "TRUE") || ($timeValue > 0)) {
$parameter->setValue("ICS2 (Image Cytometry Standard 2)");
$_SESSION['first_visit'] = false;
}
}
?>
<select name="OutputFileFormat"
id="OutputFileFormat"
class="selection"
title="Output file format"
size="1">
<?php
// FILTER POSSIBLE OUTPUT FILE FORMATS
// Extract possible values for OutputFileFormat
$possibleValues = $parameter->possibleValues();
sort($possibleValues);
// If the dataset is multi-channel, we remove the TIFF-16 bit
// options from the list
/** @var NumberOfChannels $nChannelsParameter */
$nChannelsParameter = $_SESSION['setting']->parameter("NumberOfChannels");
$numberOfChannels = $nChannelsParameter->value();
if ($numberOfChannels > 1) {
$possibleValues = array_diff($possibleValues, array('TIFF 16-bit'));
$possibleValues = array_diff($possibleValues, array('TIFF 8-bit'));
$possibleValues = array_values($possibleValues);
}
// If the dataset is single-channel or has more than 3 channels, we remove
// the RGB TIFF 8-bit option from the list
$nChannelsParameter = $_SESSION['setting']->parameter("NumberOfChannels");
$numberOfChannels = $nChannelsParameter->value();
if (($numberOfChannels == 1) || ($numberOfChannels > 3)) {
$possibleValues = array_diff($possibleValues, array('RGB TIFF 8-bit'));
$possibleValues = array_values($possibleValues);
}
// If the dataset is a time series, we remove TIFF 8, TIFF RGB and TIFF 16
// from the list
if (($_SESSION['autoseries'] == "TRUE") || ($timeValue > 0)) {
$possibleValues = array_diff($possibleValues, array('TIFF 16-bit'));
$possibleValues = array_diff($possibleValues, array('TIFF 8-bit'));
$possibleValues = array_diff($possibleValues, array('RGB TIFF 8-bit'));
$possibleValues = array_values($possibleValues);
}
// if 'first visit' is not set, set the OutputFileFormat to the default chosen by the admin.
// See config files.
if (!isset($_SESSION['first_visit'])) {
global $default_output_format;
/* Notice that unfortunately 'values-translations' are inverted in
parameter "OutputFileFormat" w.r.t "ImageFileFormat". Therefore, a
translation is needed here. */
$defaultFormatSet = False;
foreach ($possibleValues as $possibleValue) {
if ($parameter->translatedValueFor($possibleValue) == $default_output_format) {
$parameter->setValue($possibleValue);
$defaultFormatSet = True;
break;
}
}
/* Fallback */
if ($defaultFormatSet === False) {
$parameter->setValue("ICS2 (Image Cytometry Standard 2)");
}
$_SESSION['first_visit'] = false;
}
// Set the OutputFileFormat in the TaskSetting object
$_SESSION['task_setting']->set($parameter);
foreach ($possibleValues as $possibleValue) {
if ($possibleValue == $parameter->value()) {
$selected = "selected=\"selected\"";
} else {
$selected = "";
}
?>
<option <?php echo $selected ?>>
<?php echo $possibleValue ?>
</option>
<?php
}
?>
</select>
<input name="create" type="hidden" value="create"/>
</fieldset>
</form>
<fieldset class="report">
<legend>
<a href="javascript:openWindow(
'http://www.svi.nl/HuygensRemoteManagerHelpCreateJob')">
<img src="images/help.png" alt="?"/>
</a>
<a href="select_parameter_settings.php">
Image parameters
</a>: <?php print $_SESSION['setting']->name() ?>
</legend>
<textarea name="parameter_settings_report"
title="Summary"
class="selection"
cols="50"
rows="5"
readonly="readonly">
<?php
echo $_SESSION['setting']->displayString();
?>
</textarea>
</fieldset>
<fieldset class="report">
<legend>
<a href="javascript:openWindow(
'http://www.svi.nl/HuygensRemoteManagerHelpCreateJob')">
<img src="images/help.png" alt="?"/>
</a>
<a href="select_task_settings.php">
Processing parameters
</a>: <?php echo $_SESSION['task_setting']->name() ?>
</legend>
<textarea name="task_settings_report"
title="Summary"
class="selection"
cols="50"
rows="5"
readonly="readonly">
<?php
$numberOfChannels = $_SESSION['setting']->numberOfChannels();
$micrType = $_SESSION['setting']->microscopeType();
$timeInterval = $_SESSION['setting']->sampleSizeT();
echo $_SESSION['task_setting']->displayString($numberOfChannels, $micrType, $timeInterval);
?>
</textarea>
</fieldset>
<fieldset class="report">
<legend>
<a href="javascript:openWindow(
'http://www.svi.nl/HuygensRemoteManagerHelpCreateJob')">
<img src="images/help.png" alt="?"/>
</a>
<?php if (System::hasLicense("coloc")) { ?>
<a href="select_analysis_settings.php">
<?php } else { ?>
<a>
<?php } ?>
Analysis parameters
</a>: <?php echo $_SESSION['analysis_setting']->name() ?>
</legend>
<textarea name="analysis_settings_report"
title="Summary"
class="selection"
cols="50"
rows="5"
readonly="readonly">
<?php
echo $_SESSION['analysis_setting']->displayString();
?>
</textarea>
</fieldset>
<fieldset class="report">
<legend>
<a href="javascript:openWindow(
'http://www.svi.nl/HuygensRemoteManagerHelpCreateJob')">
<img src="images/help.png" alt="?"/>
</a>
<a href="select_images.php">
Selected images
</a>
</legend>
<textarea name="task_settings_report"
title="Summary"
class="selection"
cols="50"
rows="3"
readonly="readonly">
<?php
// Show the files selected.
$files = $_SESSION['fileserver']->selectedFiles();
foreach ($files as $file) {
echo " " . $file . "\n";
}
?>
</textarea>
</fieldset>
<form method="post" action="">
<div id="controls">
<?php
if (!isset($_SESSION['jobcreated'])) {
?>
<input type="button" name="previous" value=""
class="icon previous"
onclick="goBack()"
onmouseover="TagToTip('ttSpanBack' )"
onmouseout="UnTip()"/>
<input type="button" name="create job" value=""
class="icon launch_start"
onclick="submitJob()"
onmouseover="TagToTip('ttSpanCreateJob' )"
onmouseout="UnTip()"/>
<?php
}
?>
</div>
</form>
</div> <!-- content -->
<div id="rightpanel">
<div id="info">
<h3>Quick help</h3>
<p>As a last step, please choose the output file format for your
restored images.</p>
<p>Please notice that some output file formats cannot be selected
under specific circumnstances. For example, TIFF is disabled for
images with more than 3 channels, and also for time series.</p>
<p>Also, use this as summary to check your parameters. If you spot
a mistake, use the links on the left to go back and fix it.</p>
<p>Once you are okay with the parameters, press the
<img src="images/launch_start.png" alt="Create job" width="22"
height="22"/> <b>launch job</b> button to add the job to the
queue and go back to
the home page.</p>
<?php
if ($numberOfChannels > 1) {
echo "<p>Please notice that is not possible to save " .
"multichannel datasets in TIFF-16 bit format.</p>";
}
?>
</div>
<div id="message">
<?php
echo "<p>$message</p>";
if (!$_SESSION['fileserver']->checkSanitization()) {
echo "<p>Warning: files containing special characters in their " .
"names have been selected. These files will automatically " .
"be renamed on disk if you continue.</p>" .
"<p>For example a file called \"B@d img(náme).h5\" " .
"would be renamed to \"B_d_img_n__me_.h5\".</p>";
}
?>
</div>
</div> <!-- rightpanel -->
<!-- Short script to make sure the user does not navigate away until he has submitted.
We just set a variable canLeave to true when we should not display the warning.
The warning comes from the onbeforeunload function. This is hard-coded into Firefox so
the custom message does not display. In other browsers, the message here should show. -->
<script type="text/javascript">
var canLeave = false;
function submitJob() {
canLeave = true;
document.forms['createjob'].submit();
}
function goBack() {
canLeave = true;
document.location.href = '<?php echo $goBackLink; ?>';
}
// Check if the user is quitting it
window.onbeforeunload = function (e) {
if (!canLeave) {
document.forms['createjob'].is;
return 'You did not submit the job. Are you sure you want to exit?';
}
};
</script>
<?php
include("footer.inc.php");
?>