Skip to content

Commit 6a606bb

Browse files
committed
implemented working stock mechanism
add state hiccup
1 parent befa7a3 commit 6a606bb

9 files changed

+1238
-637
lines changed

SensorAbstraction.php

+352-276
Large diffs are not rendered by default.

StateAbstraction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getState()
3131
"updated" => "0",
3232
"created" => "0"
3333
);
34-
34+
3535
if(is_null($this->dbConn))
3636
{
3737
// Database connection not initialised

_cache.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ public function updateSpaceApi( $_spaceAPI )
2020
}
2121
}
2222
?>
23+

audit.html

+441
Large diffs are not rendered by default.

geo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ function $( _o )
9292
<body>
9393
<pre id="info">initializing..</pre>
9494
</body>
95-
</html>
95+
</html>

index.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,26 @@
1818
debug : adds some debug information (breaks JSON)
1919
*/
2020

21+
// xopr: Enable debugging (when shit hits the fan again)
22+
if ( getVar( "debug" ) !== false )
23+
{
24+
error_reporting( -1 );
25+
ini_set( 'display_errors', 1 );
26+
}
27+
2128
require "StateAbstraction.php";
2229
require "SensorAbstraction.php";
2330

2431
// Include API key
2532
include( $_SERVER['DOCUMENT_ROOT']."/../spaceAPI_config.php" );
2633

2734
// Send headers immediately
28-
header('Content-Type: application/json');
29-
header('Content-Type: text/html; charset=utf-8');
35+
header( "Access-Control-Allow-Origin: *" );
36+
header( "Access-Control-Allow-Methods: GET" );
37+
header( "Content-Type: application/json" );
38+
header( 'Content-Type: text/javascript; charset="UTF-8"' );
39+
//header( "Content-Type: text/html; charset=utf-8" );
40+
3041

3142
$stateAbstraction = new StateAbstraction();
3243
$stateAbstraction->init();

sensors.php

+24-6
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public function updateSpaceApi( $_spaceAPI )
242242

243243
public function updateDatabase( )
244244
{
245+
// Audit/correct using this:
246+
// https://ackspace.nl/spaceAPI/?key=API_KEY&address=premiumcola&update=sensors&type=audit&value=1&location=1&user=xopr
247+
// https://ackspace.nl/spaceAPI/?key=API_KEY&address=premiumcola&update=sensors&type=correct&value=1
248+
245249
global $sensorAbstraction;
246250

247251
//Gather the information to load into the database
@@ -253,6 +257,9 @@ public function updateDatabase( )
253257
$arrLon = getVar( "lon" );
254258
$arrAccuracy = getVar( "accuracy" );
255259

260+
$arrUser = getVar( "user" ); // string
261+
$arrLocation = getVar( "location" ); // id
262+
256263
if ( !is_array( $arrAddress ) )
257264
$arrAddress = Array( $arrAddress );
258265
if ( !is_array( $arrValue ) )
@@ -267,6 +274,11 @@ public function updateDatabase( )
267274
if ( !is_array( $arrAccuracy ) )
268275
$arrAccuracy = Array( $arrAccuracy );
269276

277+
if ( !is_array( $arrLocation ) )
278+
$arrLocation = Array( $arrLocation );
279+
if ( !is_array( $arrUser ) )
280+
$arrUser = Array( $arrUser );
281+
270282
$success = true;
271283

272284
foreach ( $arrAddress as $idx => $address )
@@ -300,30 +312,36 @@ public function updateDatabase( )
300312
$success = false;
301313
break;
302314

303-
case "audit":
315+
case "audit":
304316
if ( getVar( "debug" ) !== false )
305-
print_r( "AUDIT\n".$arrAddress[ $idx ]."##".$arrValue[ $idx ]."##\n" );
317+
print_r( "AUDIT\n".$arrAddress[ $idx ]."##".$arrValue[ $idx ]."##".$arrLocation[ $idx ]."##".$arrUser[ $idx ]."##\n" );
306318

319+
// Barcode, amount, location id, user
307320
if ( !isset( $arrAddress[ $idx ] ) )
308321
continue;
309322
if ( !isset( $arrValue[ $idx ] ) )
310323
continue;
324+
if ( !isset( $arrLocation[ $idx ] ) )
325+
continue;
326+
if ( !isset( $arrUser[ $idx ] ) )
327+
continue;
311328

312-
if ( !$sensorAbstraction->updateStock( $arrAddress[ $idx ], $arrValue[ $idx ], true ) )
329+
if ( !$sensorAbstraction->updateStock( $arrAddress[ $idx ], $arrValue[ $idx ], true, $arrLocation[ $idx ], $arrUser[ $idx ] ) )
313330
$success = false;
314331
break;
315332

316-
case "correct":
333+
case "correct":
317334
if ( getVar( "debug" ) !== false )
318335
print_r( "CORRECT\n".$arrAddress[ $idx ]."##".$arrValue[ $idx ]."##\n" );
319336

337+
// Barcode
320338
if ( !isset( $arrAddress[ $idx ] ) )
321339
continue;
322340
if ( !isset( $arrValue[ $idx ] ) )
323341
continue;
324342

325-
// Correct (not audit)
326-
if ( !$sensorAbstraction->updateStock( $arrAddress[ $idx ], $arrValue[ $idx ], false ) )
343+
// Correct (not audit, note that location and user are not used)
344+
if ( !$sensorAbstraction->updateStock( $arrAddress[ $idx ], $arrValue[ $idx ], false, null, null ) )
327345
$success = false;
328346
break;
329347
}

0 commit comments

Comments
 (0)