-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage1process.php
86 lines (63 loc) · 2.35 KB
/
page1process.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
<!DOCTYPE html>
<html>
<head>
<title>Page1</title>
<link href="css/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<?php include 'header.php'; // Place header for our framework ?>
<body>
<?php
// Start the php session to be able to pull login and password tokens
session_start();
$username=$_SESSION['login'];
$password=$_SESSION['password'];
$token=$_SESSION['token'];
$job_name=$_POST['job_name'];
$output_name=$_POST['output_location'];
//Create a php curl object
$ch = curl_init();
//Base url for foundation api for php curl to launch a job
$job_url = 'https://foundation.iplantcollaborative.org/apps-v1/job';
$ch_values = "$username:$password";
//Set php curl options.
curl_setopt($ch, CURLOPT_URL,$job_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $ch_values);
curl_setopt($ch, CURLOPT_POST, true);
//Setting the base postField. Here we are starting software name of the application.
//TODO CHANGE APPLICATION NAME TO MAKE SURE PROPER SOFTWARE IS CALLED
$postField ="softwareName=APPNAMEHERE&archive=true";
//HARD CODE CALLBACK URL HERE. MAKE SURE TO CHANGE THIS TO THE IP ADDRESS OF THAT HIS SCRIPT IS INSTALLED
$postField="$postField&callbackURL=URLHERE/done.php";
//Going through all the input form from process.php that user entered. Then adds it to the baseField.
foreach($_POST as $name => $value) {
if($value != ""){
$postField = "$postField&$name=$value";
}
}
//Sets the postField as an option for our php curl request
curl_setopt($ch, CURLOPT_POSTFIELDS, $postField);
//Execute the php curl and grab the response
$response = curl_exec($ch);
$resultStatus = curl_getinfo($ch);
//Turn the response into json which php can manipulate
$handled_json = json_decode($response,true);
//If the php curl was successful, display the results, if not, print failed results
if($resultStatus['http_code'] == 200) {
$job_id=$handled_json['result']['id'];
$status=$handled_json['result']['status'];
echo "$response <br />";
echo "<br />";
echo "<h2>Your Job ID is $job_id</h2><br />";
echo "<h2>Your Job Status is $status</h2><br />";
}
else { //Here it failed
echo '<h3>Call Failed</h3> '.print_r($resultStatus);
echo "$response";
}
//destroy php curl object
curl_close ($ch);
?>
</body>
</html>