-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
index.php
219 lines (196 loc) · 6.06 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
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
<?php
/**
* Copyright (c) 2017, Thomas Schoffelen BV.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
use PKPass\PKPass;
require('../../vendor/autoload.php');
if(isset($_POST['passenger'])) {
// User has filled in the flight info, so create the pass now
// Predefined data
$labels = [
'SFO' => 'San Francisco',
'LAX' => 'Los Angeles',
'LHR' => 'London',
];
$gates = ['F12', 'G43', 'A2', 'C5', 'K9'];
// User-set vars
$passenger = addslashes($_POST['passenger']);
$origin = $_POST['origin'];
$origin_label = $labels[$origin];
$destination = $_POST['destination'];
$destination_label = $labels[$destination];
$gate = $gates[array_rand($gates)]; // Yup, pick a random gate
$date = date('m/d/Y H:i', $_POST['date']); // Convert date to string
// Create pass
//Set certificate and path in the constructor
$pass = new PKPass('../../Certificates.p12', 'password');
// Set pass data
$pass->setData('{
"passTypeIdentifier": "pass.com.scholica.flights",
"formatVersion": 1,
"organizationName": "Flight Express",
"serialNumber": "123456",
"teamIdentifier": "KN44X8ZLNC",
"backgroundColor": "rgb(32,110,247)",
"logoText": "FLIGHT_INFO_LABEL",
"description": "Demo pass",
"boardingPass": {
"primaryFields": [
{
"key" : "origin",
"label" : "' . $origin_label . '",
"value" : "' . $origin . '"
},
{
"key" : "destination",
"label" : "' . $destination_label . '",
"value" : "' . $destination . '"
}
],
"secondaryFields": [
{
"key": "gate",
"label": "GATE_LABEL",
"value": "' . $gate . '"
},
{
"key": "date",
"label": "DEPARTURE_DATE_LABEL",
"value": "' . $date . '"
}
],
"backFields": [
{
"key": "passenger-name",
"label": "Passenger",
"value": "' . $passenger . '"
}
],
"transitType" : "PKTransitTypeAir"
},
"barcode": {
"format": "PKBarcodeFormatQR",
"message": "Flight-Gate' . $gate . '-' . $date . '-' . $passenger . '-' . $destination . '",
"messageEncoding": "iso-8859-1"
},
"relevantDate": "' . date('Y-m-d\TH:i:sP', $_POST['date']) . '"
}');
// Add files to the PKPass package
$pass->addFile('../images/icon.png');
$pass->addFile('../images/[email protected]');
$pass->addFile('../images/logo.png');
// Specify english and french localizations
$pass->addFile('en.strings', 'en.lproj/pass.strings');
$pass->addFile('fr.strings', 'fr.lproj/pass.strings');
// Create and output the PKPass
// If you pass true, the class will output the zip into the browser.
$pass->create(true);
} else {
// User lands here, there are no $_POST variables set
?>
<html>
<head>
<title>Flight pass creator - PHP class demo</title>
<meta name="viewport" content="width=320; user-scalable=no"/>
<style>
body {
font-family: Helvetica, sans-serif;
}
.header {
color: white;
background-color: #6699cc;
padding-top: 30px;
padding-bottom: 30px;
margin-bottom: 32px;
text-align: center;
}
.logo {
width: 64px;
height: 64px;
margin-bottom: 20px;
}
.title {
color: white;
font-size: 22px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
font-weight: bold;
display: block;
text-align: center;
}
.userinfo {
margin: 0 auto;
padding-bottom: 32px;
width: 280px;
}
form.form-stacked {
padding: 0;
}
legend {
text-align: center;
padding-bottom: 25px;
clear: both;
border-bottom: none;
}
input.xlarge {
width: 280px;
height: 26px;
line-height: 26px;
}
</style>
</head>
<body>
<div class="header">
<img class="logo" src="icon.png"/> <span class="title">Air Company</span>
</div>
<div class="userinfo">
<form action="index.php" method="post" class="form-stacked">
<fieldset>
<legend style="padding-left: 0;">Please enter your info</legend>
<div class="clearfix">
<label style="text-align:left">Flight schedule</label>
<div class="input">
<select name="origin" style="width: auto;">
<option value="SFO">San Francisco</option>
<option value="LAX">Los Angeles</option>
<option value="LHR">London</option>
</select> to <select name="destination" style="width: auto;">
<option value="SFO">San Francisco</option>
<option value="LAX">Los Angeles</option>
<option value="LHR">London</option>
</select>
</div>
</div>
<div class="clearfix">
<label style="text-align:left">Passenger name</label>
<div class="input">
<input class="xlarge" name="passenger" type="text" value="" placeholder="John Appleseed"/>
</div>
</div>
<div class="clearfix">
<label style="text-align:left">Flight date</label>
<div class="input">
<select name="date" style="width: 100%;">
<option value="<?= time(); ?>">Today</option>
<option value="<?= (time() + 86400); ?>">Tomorrow</option>
<option value="<?= (time() + (86400 * 7)); ?>">Next week</option>
</select>
</div>
</div>
<br/><br/>
<center><input type="submit" class="btn primary" value=" Create pass > "/></center>
</fieldset>
</form>
</div>
</body>
</html>
<?php } ?>