$rows["message"] = "Inscription ajoutée !"; } else { $rows["message"] = "Déjà inscrit !"; } } else { $rows["status"] = "error"; $rows["message"] = "Nombre limite atteint !"; } echoResponse(200, $rows); }); $app->put('/agendas/:idAgenda', function ($idAgenda) use($app) { $data = json_decode($app->request->getBody()); $condition = array('idAgenda' => $idAgenda); $mandatory = array(); global $db; $rows = $db->update("agenda", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Agenda modifié !"; } echoResponse(200, $rows); }); $app->put('/ajoutcreateurs/:mail', function ($mail) use($app) { $data = array("createurAg" => 1); $condition = array('mail' => $mail); $mandatory = array(); global $db; $rows = $db->update("personne", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Createur ajouté !"; } echoResponse(200, $rows);
$app->post('/products', function () use($app) { $data = json_decode($app->request->getBody()); $mandatory = array('name'); global $db; $rows = $db->insert("products", $data, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product added successfully."; } echoResponse(200, $rows); }); $app->put('/products/:id', function ($id) use($app) { $data = json_decode($app->request->getBody()); $condition = array('id' => $id); $mandatory = array(); global $db; $rows = $db->update("products", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product information updated successfully."; } echoResponse(200, $rows); }); $app->delete('/products/:id', function ($id) { global $db; $rows = $db->delete("products", array('id' => $id)); if ($rows["status"] == "success") { $rows["message"] = "Product removed successfully."; } echoResponse(200, $rows); }); function echoResponse($status_code, $response) {
$app->post('/companies', function () use($app) { $data = json_decode($app->request->getBody()); $mandatory = array('Name', 'Address', 'City', 'Country'); global $db; $rows = $db->insert("companies", $data, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Company added successfully."; } echoResponse(200, $rows); }); $app->put('/companies/:id', function ($id) use($app) { $data = json_decode($app->request->getBody()); $condition = array('CompanyID' => $id); $mandatory = array(); global $db; $rows = $db->update("companies", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Company information updated successfully."; } echoResponse(200, $rows); }); $app->delete('/companies/:id', function ($id) { global $db; $rows = $db->delete("companies", array('CompanyID' => $id)); if ($rows["status"] == "success") { $rows["message"] = "Company removed successfully."; } echoResponse(200, $rows); }); function echoResponse($status_code, $response) {
//end switch } else { //error_log("$time [$script_name] [rtbh] [$remote_addr-$myuser] [no chain specified]\n", 3, $log_file); $error = " invalid params "; $status = "ERROR"; $message = $error; } if ($error === "") { /* select row from DB */ $del_user = $_SESSION['USER']; $rows = $db->select6($table_name, array('id' => "{$id}")); /* make sure we have at leats 1 row . If not it means rowid not in DB */ if (count($rows['data']) > 0) { $sourceip = $rows['data'][0]['ip']; /* keep track of the user deleting the row */ $rows = $db->update($table_name, array('insertby' => "{$del_user}"), array('id' => "{$id}"), array('insertby')); /* delete the row */ $rows = $db->delete($table_name, array('id' => "{$id}")); $status = $rows['status']; $message = $rows['message'] . ", {$sourceip} deleted."; } else { $error = " row id does not exist "; $status = "ERROR"; $message = $error; } } ?> <!doctype html> <html lang="en-US"> <head> <meta charset="utf-8" />
$app->post('/bolas', function () use($app) { $data = json_decode($app->request->getBody()); $mandatory = array('code'); global $db; $rows = $db->insert("bolas", $data, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product added successfully."; } echoResponse(200, $rows); }); $app->put('/bolas/:id', function ($id) use($app) { $data = json_decode($app->request->getBody()); $condition = array('id' => $id); $mandatory = array(); global $db; $rows = $db->update("bolas", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product information updated successfully."; } echoResponse(200, $rows); }); $app->delete('/bolas/:id', function ($id) { global $db; $rows = $db->delete("bolas", array('id' => $id)); if ($rows["status"] == "success") { $rows["message"] = "Product removed successfully."; } echoResponse(200, $rows); }); $app->get('/personas', function () { global $db;
$db->deleteWhere("overtime", "id='" . $piece . "' AND player='" . $game['turn'] . "'"); } if (sizeof($newLockouts) > 0) { // insert lockouts $db->insert("lockouts", $newLockouts); if ($jumpedPieces) { // delete jumped pieces $db->deleteIn("played", "tile", $jumpedPieces['tiles']); // delete lockouts from jumped pieces $db->deleteWhereAll("lockouts", array('fromTile', 'toTile'), $jumpedPieces['tiles'], "OR"); // add jumped pieces to overtime bins $db->insert("overtime", $overtimePieces); } } // update player turn $db->update("game", array('turn' => $nextPlayer), array('gameID' => $gameID)); // set overtime? if ($newStatus) { $db->update("game", array('status' => $newStatus), array('gameID' => $gameID)); } $db->commitTransaction(); } catch (Exception $e) { $db->rollBackTransaction(); echo "Failed: " . $e->getMessage(); } // everything was successful, return updated state // $updates = array( // 'turn' => $nextPlayer, // 'lockouts' => $newLockouts, // 'played' => $newPieces, // 'jumped' => $jumpedPieces
$app->post('/products', function () use($app) { $data = json_decode($app->request->getBody()); // $mandatory = array('name'); global $db; $rows = $db->insert("inventory", $data, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product added successfully."; } echoResponse(200, $rows); }); $app->put('/products/:id', function ($id) use($app) { $data = json_decode($app->request->getBody()); $condition = array('id' => $id); $mandatory = array(); global $db; $rows = $db->update("inventory", $data, $condition, $mandatory); if ($rows["status"] == "success") { $rows["message"] = "Product information updated successfully."; } echoResponse(200, $rows); }); $app->delete('/products/:id', function ($id) { global $db; $rows = $db->delete("inventory", array('id' => $id)); if ($rows["status"] == "success") { $rows["message"] = "Product removed successfully."; } echoResponse(200, $rows); }); function echoResponse($status_code, $response) {