-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
299 lines (243 loc) · 10.7 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
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
<!DOCTYPE html>
<?php
$qr=false;
$meal_name='QRFood - QRcode generator that contains meals nutritional informations for your menus';
// converts string to hexadecimal string (for foursquare id)
function str2hex($hex)
{
$tmp='';
for ($i = 0; $i < strlen($hex); $i++) {
$tmp .= (dechex(ord(substr($hex,$i,1))));
}
return $tmp;
}
if(strlen($_SERVER["REQUEST_URI"])>1 && strpos($_SERVER["REQUEST_URI"],'/index.php')===false){
$qr=true;
// decode base64 data
$data= base64_decode(substr($_SERVER["REQUEST_URI"],1));
// name is after 32nd byte
$meal_name = substr($data,32);
// foursquare id is between byte 20 and byte 32
$foursquare_id=str2hex(substr($data,20,12));
// get all int values
$weight = ord(substr($data,0,1))*256+ord(substr($data,1,1));
$calories = ord(substr($data,2,1))*256+ord(substr($data,3,1));
$saturated_fat = ord(substr($data,4,1))*256+ord(substr($data,5,1));
$unsaturated_fat = ord(substr($data,6,1))*256+ord(substr($data,7,1));
$sodium = ord(substr($data,8,1))*256+ord(substr($data,9,1));
$carbohydrates = ord(substr($data,10,1))*256+ord(substr($data,11,1));
$fiber = ord(substr($data,12,1))*256+ord(substr($data,13,1));
$sugar = ord(substr($data,14,1))*256+ord(substr($data,15,1));
$protein = ord(substr($data,16,1))*256+ord(substr($data,17,1));
$cholesterol = ord(substr($data,18,1))*256+ord(substr($data,19,1));
// create QRCode with phpqrcode
$PHPQRCODE_DIR = 'phpqrcode';
//set it to writable location, a place for temp generated PNG files
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.$PHPQRCODE_DIR.DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
//html PNG location prefix
$PNG_WEB_DIR = 'temp/';
include $PHPQRCODE_DIR.DIRECTORY_SEPARATOR."qrlib.php";
$filename = $PNG_TEMP_DIR.'test.png';
$errorCorrectionLevel = 'L';
$matrixPointSize = 3;
$filename = $PNG_TEMP_DIR.'QRFood_'.md5($_SERVER["REQUEST_URI"].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png('http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
//$filename2 = $PNG_TEMP_DIR.'QRFood_'.md5($data.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
//QRcode::png($data, $filename2, $errorCorrectionLevel, $matrixPointSize, 2);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo($meal_name); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen" />
<link href="css/qrfood.css" rel="stylesheet" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="/js/html5shiv.js"></script>
<script src="/js/respond.min.js"></script>
<![endif]-->
<script src="/qrfood.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><span class="glyphicon glyphicon-qrcode"></span> QRFood <span class="glyphicon glyphicon-cutlery"></span> </a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="https://github.com/Keeward/qrfood">Get source code</a></li>
</ul>
</div><!--/.navbar-collapse -->
</div>
</div>
<div class="container" style="margin-top: 70px;">
<?php
//display generated file
if($qr) {
echo '<button class="btn btn-primary" onclick="setQRValues('."'".$meal_name."'".', '."'".$foursquare_id."'".', '.$weight.', '.$calories.', '.$saturated_fat.', '.$unsaturated_fat.', '.$sodium.', '.$carbohydrates.', '.$fiber.', '.$sugar.', '.$protein.', '.$cholesterol.');" style="float: right;"><span class="glyphicon glyphicon-pencil"></span> Edit</button>';
echo '<table class="table-bordered">';
echo '<tr>';
echo '<td rowspan="3"><img src="'.$PHPQRCODE_DIR.DIRECTORY_SEPARATOR.$PNG_WEB_DIR.basename($filename).'" alt="QRFood" /></td>';
echo '<td colspan="5">';
echo '<span style="float: left;"><h5>'.$meal_name.'</h5></span>';
echo '<span style="float: right;"><a href="https://foursquare.com/v/'.$foursquare_id.'" target="_blank" title="'.$foursquare_id.'"><img src="foursquare.png" alt="'.$foursquare_id.'" /></a></span>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td><h6><span class="label label-default">weight</span> '.$weight.'</h6></td>';
echo '<td><h6><span class="label label-default">Kcal</span> '.$calories.'</h6></td>';
echo '<td><h6><span class="label label-default">sat. fat</span> '.$saturated_fat.'</h6></td>';
echo '<td><h6><span class="label label-default">uns. fat</span> '.$unsaturated_fat.'</h6></td>';
echo '<td><h6><span class="label label-default">sodium</span> '.$sodium.'</h6></td>';
echo '</tr>';
echo '<tr>';
echo '<td><h6><span class="label label-default">carbs</span> '.$carbohydrates.'</h6></td>';
echo '<td><h6><span class="label label-default">fiber</span> '.$fiber.'</h6></td>';
echo '<td><h6><span class="label label-default">sugar</span> '.$sugar.'</h6></td>';
echo '<td><h6><span class="label label-default">protein</span> '.$protein.'</h6></td>';
echo '<td><h6><span class="label label-default">cholesterol</span> '.$cholesterol.'</h6></td>';
echo '</tr>';
echo '</table>';
}
?>
<form method="get" class="form-horizontal" role="form" onsubmit="return(qrSubmit());">
<fieldset>
<!-- Form Name -->
<legend>QRFood</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-lg-3 control-label">Name of the meal</label>
<div class="col-lg-9 input-append">
<input type="text" class="form-control span2" id="meal_name" name="meal_name" placeholder="Salade saveur, 김치, hamburger…" required="" />
<span class="help-block">Enter the complete name</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Restaurant Foursquare ID</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="foursquare_id" name="foursquare_id" placeholder="4ac759c9f964a520eab620e3" required="" />
<span class="help-block">Enter the restaurant Foursquare ID</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Weight</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="weight" name="weight" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Calories</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="calories" name="calories" placeholder="100" />
<span class="input-group-addon">Kcal</span>
</div>
<span class="help-block">per serving, in Kilocalories</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Saturated fat</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="saturated_fat" name="saturated_fat" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Unsaturated fat</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="unsaturated_fat" name="unsaturated_fat" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Sodium</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="sodium" name="sodium" placeholder="100" />
<span class="input-group-addon">mg</span>
</div>
<span class="help-block">per serving, in milligrams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Carbohydrates</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="carbohydrates" name="carbohydrates" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Fiber</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="fiber" name="fiber" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Sugar</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="sugar" name="sugar" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Protein</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="protein" name="protein" placeholder="100" />
<span class="input-group-addon">g</span>
</div>
<span class="help-block">per serving, in grams</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Cholesterol</label>
<div class="col-lg-9 input-append">
<div class="input-group">
<input type="text" class="form-control span2" id="cholesterol" name="cholesterol" placeholder="100" />
<span class="input-group-addon">mg</span>
</div>
<span class="help-block">per serving, in milligrams</span>
</div>
</div>
<div class="col-lg-3"></div>
<div class="col-lg-9 input-append"><button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-check"></span> Generate QRFood</button></div>
</fieldset>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>