Add more fields, add create capability

hi
Skylar Ittner 8 years ago
parent 83cf691a96
commit 190cd221a9

@ -7,21 +7,21 @@ $from = $_GET['from'];
require 'readfrom.php';
$id = $_GET['id'];
if (is_empty($id)) {
sendError('Missing item ID!');
}
$loc;
if ($from == 'assets') {
$loc = $database->select($from, 'rtd_location_id', ['id' => $id])[0];
if (is_empty($id) || $id == 0 || $id == null) {
$loc = '0';
} else {
$loc = $database->select($from, 'location_id', ['id' => $id])[0];
}
if ($from == 'assets') {
$loc = $database->select($from, 'rtd_location_id', ['id' => $id])[0];
} else {
$loc = $database->select($from, 'location_id', ['id' => $id])[0];
}
if ($loc == null) {
$loc = 0;
if ($loc == null) {
$loc = 0;
}
}
$list = $database->select('locations', ['id', 'name']);
array_unshift($list, ['id' => "0", name => "None/Other"]);
die(json_encode(['status' => 'OK', 'location' => $loc, 'list' => $list]));
die(json_encode(['status' => 'OK', 'location' => $loc, 'list' => $list]));

@ -0,0 +1,26 @@
<?php
require 'required.php';
//require 'dieifnotloggedin.php';
$from = $_GET['from'];
require 'readfrom.php';
$id = $_GET['id'];
if (is_empty($id) || $id == 0 || $id == null) {
$model = '0';
} else {
if ($from == 'assets') {
$model = $database->select($from, 'model_id', ['id' => $id])[0];
} else {
sendError("Command only valid for assets.");
}
if ($model == null) {
$model = 0;
}
}
$list = $database->select('models', ['id', 'name']);
die(json_encode(['status' => 'OK', 'model' => $model, 'list' => $list]));

@ -7,18 +7,18 @@ $from = $_GET['from'];
require 'readfrom.php';
$id = $_GET['id'];
if (is_empty($id)) {
sendError('Missing item ID!');
}
$status;
if ($from == 'assets') {
$status = $database->select($from, 'status_id', ['id' => $id])[0];
if (is_empty($id) || $id == 0 || $id == null) {
$status = '0';
} else {
sendError("Command only valid for assets.");
}
if ($from == 'assets') {
$status = $database->select($from, 'status_id', ['id' => $id])[0];
} else {
sendError("Command only valid for assets.");
}
if ($status == null) {
$status = 0;
if ($status == null) {
$status = 0;
}
}
$list = $database->select('status_labels', ['id', 'name', 'notes']);

@ -39,11 +39,12 @@ function authenticate_user($username, $password) {
global $database;
$qf = 'username';
if (!username_exists($username)) {
if (!email_exists($username)) {
return false;
} else {
$qf = 'email';
}
// if (!email_exists($username)) {
// return false;
// } else {
// $qf = 'email';
// }
return false;
}
$hash = $database->select('users', ['password'], [$qf => $username])[0]['password'];
return (password_verify($password, $hash));

@ -7,13 +7,23 @@ $from = $_POST['from'];
require 'readfrom.php';
$id = $_POST['id'];
if (is_empty($id)) {
sendError('Missing item ID!');
if (is_empty($_POST['asset_tag'])) {
sendError('Please fill in an asset tag.');
}
if ($from == 'assets') {
$database->update($from, ['name' => $_POST['name'], 'rtd_location_id' => $_POST['location'], 'order_number' => $_POST['order_number'], 'status_id' => $_POST['status']], ['id' => $id]);
if (is_empty($id)) {
if ($from == 'assets') {
$user_id = $database->select('users', 'id', ['username' => $_SESSION['user']])[0];
$database->insert($from, ['name' => $_POST['name'], 'user_id' => $user_id, 'asset_tag' => $_POST['asset_tag'], 'rtd_location_id' => $_POST['location'], 'order_number' => $_POST['order_number'], 'status_id' => $_POST['status'], 'serial' => $_POST['serial'], 'model_id' => $_POST['model'], '#updated_at' => 'NOW()', '#created_at' => 'NOW()', '_snipeit_hard_drive_secure__y_n_' => $_POST['hdd_secure']]);
} else {
$database->insert($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number'], '#updated_at' => 'NOW()', '#created_at' => 'NOW()']);
}
} else {
$database->update($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number']], ['id' => $id]);
}
if ($from == 'assets') {
$database->update($from, ['name' => $_POST['name'], 'asset_tag' => $_POST['asset_tag'], 'rtd_location_id' => $_POST['location'], 'order_number' => $_POST['order_number'], 'status_id' => $_POST['status'], 'serial' => $_POST['serial'], 'model_id' => $_POST['model'], '#updated_at' => 'NOW()', '_snipeit_hard_drive_secure__y_n_' => $_POST['hdd_secure']], ['id' => $id]);
} else {
$database->update($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number'], '#updated_at' => 'NOW()'], ['id' => $id]);
}
}
sendOK();

Loading…
Cancel
Save