function makeBinFromRaw($binRaw, $lang = "en") { include_once "bintypes.php"; include_once "databasefunctions.php"; $newBin = new Collection(); $newBin->BinId = (int) $binRaw[0]; $newBin->OwnerId = (int) $binRaw[1]; $newBin->Name = html_entity_decode($binRaw[2], ENT_QUOTES); $newBin->Type = new BinTypeAndIDPair((int) $binRaw[3], binTypes($binRaw[3], $lang)); $newBin->BatteryLevel = (double) $binRaw[4]; $newBin->CurrentWeight = 0; $history = GetBinHistory((int) $binRaw[0]); $highest = 0; for ($i = 0; $i < count($history); $i++) { if ($history[$i][3] > $highest) { $highest = $history[$i][3]; $newBin->CurrentWeight = (int) $history[$i][2]; } } return $newBin; }
array_push($errors, "Weight not set"); $success = false; } if ($newTimestamp == "") { array_push($errors, "Timestamp not set"); $success = false; } if ($success) { RegisterNewHistory($newId, $newWeight, $newTimestamp); echo '{"success":"Stamp successfully registered"}'; } else { echo '{"errors":' . json_encode($errors) . '}'; } } else { if (isset($_GET["id"]) && !is_array($_GET["id"])) { $histRaw = GetBinHistory($_GET["id"], isset($_GET["from"]) ? $_GET["from"] : 0, isset($_GET["to"]) ? $_GET["to"] : 0); $history = []; $returnObject = new Collection(); for ($i = 0; $i < count($histRaw); $i++) { $newHist = new Collection(); $newHist->BinId = (int) $histRaw[$i][1]; $newHist->Weight = (int) $histRaw[$i][2]; $newHist->UnixTimestamp = (int) $histRaw[$i][3]; $newHist->Date = date("Y-m-d", $histRaw[$i][3]); $newHist->Time = date("H:i:s", $histRaw[$i][3]); array_push($history, $newHist); } $returnObject->BinId = (int) $_GET["id"]; $returnObject->History = $history; echo json_encode($returnObject); } else {