Add comments/documentation
This commit is contained in:
parent
0b7194fdd6
commit
eadb83ceb1
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Database configuration. If running on the same machine as snipeit,
|
||||||
|
* you can probably use the same settings here.
|
||||||
|
*/
|
||||||
$database = new medoo(
|
$database = new medoo(
|
||||||
[
|
[
|
||||||
'database_type' => 'mysql',
|
'database_type' => 'mysql',
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Simple way to block people that aren't logged in.
|
||||||
|
*/
|
||||||
require_once 'required.php';
|
require_once 'required.php';
|
||||||
|
|
||||||
if ($_SESSION['loggedin'] !== true || is_empty($_SESSION['user'])) {
|
if ($_SESSION['loggedin'] !== true || is_empty($_SESSION['user'])) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Dump a database row for a given asset/accessory/consumable
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
require 'dieifnotloggedin.php';
|
require 'dieifnotloggedin.php';
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Get a list of all locations, and the location for a given id if any.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
//require 'dieifnotloggedin.php';
|
//require 'dieifnotloggedin.php';
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Get all the models.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
//require 'dieifnotloggedin.php';
|
//require 'dieifnotloggedin.php';
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Get all status types.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
//require 'dieifnotloggedin.php';
|
//require 'dieifnotloggedin.php';
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Handles login requests, authentication, and session creation.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
|
|
||||||
|
// For lazy browser testing
|
||||||
//$_POST = $_GET;
|
//$_POST = $_GET;
|
||||||
|
|
||||||
$user = $_POST['user'];
|
$user = $_POST['user'];
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Filter table info to sane choices. You could add aliases if you like.
|
||||||
|
* The app uses all of these variations because I'm lazy and just pass label text.
|
||||||
|
*/
|
||||||
switch ($from) {
|
switch ($from) {
|
||||||
case 'accessories':
|
case 'accessories':
|
||||||
case 'accessory':
|
case 'accessory':
|
||||||
|
29
required.php
29
required.php
@ -1,12 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
ob_start();
|
ob_start(); // No worries about sending headers before/after content
|
||||||
session_start();
|
session_start();
|
||||||
require 'vendor/autoload.php';
|
|
||||||
require 'database.php';
|
|
||||||
|
|
||||||
define('JSON', true);
|
require 'vendor/autoload.php'; // Load database stuff from Composer
|
||||||
header('Content-Type: application/json');
|
require 'database.php'; // Load database settings
|
||||||
|
|
||||||
|
define('JSON', true); // Don't touch this or Something Bad might happen.
|
||||||
|
header('Content-Type: application/json'); // Don't touch this either.
|
||||||
|
|
||||||
|
// Completely disable CORS stuff, everything is allowed. You could change this
|
||||||
|
// if you know exactly what domain traffic is coming from.
|
||||||
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
|
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
|
||||||
header('Access-Control-Allow-Credentials: true');
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
|
||||||
@ -39,11 +43,6 @@ function authenticate_user($username, $password) {
|
|||||||
global $database;
|
global $database;
|
||||||
$qf = 'username';
|
$qf = 'username';
|
||||||
if (!username_exists($username)) {
|
if (!username_exists($username)) {
|
||||||
// if (!email_exists($username)) {
|
|
||||||
// return false;
|
|
||||||
// } else {
|
|
||||||
// $qf = 'email';
|
|
||||||
// }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$hash = $database->select('users', ['password'], [$qf => $username])[0]['password'];
|
$hash = $database->select('users', ['password'], [$qf => $username])[0]['password'];
|
||||||
@ -59,6 +58,11 @@ function is_empty($str) {
|
|||||||
return (!isset($str) || $str == '' || $str == null);
|
return (!isset($str) || $str == '' || $str == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a generic OK message.
|
||||||
|
* @param string $message Optional message text.
|
||||||
|
* @param boolean $die End execution after sending message (default true).
|
||||||
|
*/
|
||||||
function sendOK($message = "", $die = true) {
|
function sendOK($message = "", $die = true) {
|
||||||
if (!is_empty($message) && JSON) {
|
if (!is_empty($message) && JSON) {
|
||||||
echo '{ "status": "OK", "message": "' . $message . '" }';
|
echo '{ "status": "OK", "message": "' . $message . '" }';
|
||||||
@ -74,6 +78,11 @@ function sendOK($message = "", $die = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an error message.
|
||||||
|
* @param string $error Error text.
|
||||||
|
* @param boolean $die End execution after sending error (default true).
|
||||||
|
*/
|
||||||
function sendError($error, $die = true) {
|
function sendError($error, $die = true) {
|
||||||
if (JSON) {
|
if (JSON) {
|
||||||
echo '{ "status": "ERROR", "message": "' . $error . '" }';
|
echo '{ "status": "ERROR", "message": "' . $error . '" }';
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Search for a given term (q=) in a given category (from=) and spit out JSON.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
|
|
||||||
require 'dieifnotloggedin.php';
|
require 'dieifnotloggedin.php';
|
||||||
@ -13,6 +15,7 @@ if (is_empty($q)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$results;
|
$results;
|
||||||
|
// If you want to search through more/different fields, just add them.
|
||||||
if ($from == 'assets') {
|
if ($from == 'assets') {
|
||||||
$results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'asset_tag[~]' => $q, 'serial[~]' => $q, 'order_number[~]' => $q]]);
|
$results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'asset_tag[~]' => $q, 'serial[~]' => $q, 'order_number[~]' => $q]]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Create/update an item.
|
||||||
|
*/
|
||||||
require 'required.php';
|
require 'required.php';
|
||||||
require 'dieifnotloggedin.php';
|
require 'dieifnotloggedin.php';
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ if (is_empty($_POST['asset_tag']) && $from == 'assets') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_empty($id)) {
|
if (is_empty($id)) {
|
||||||
|
// We need to create an item
|
||||||
if ($from == 'assets') {
|
if ($from == 'assets') {
|
||||||
$user_id = $database->select('users', 'id', ['username' => $_SESSION['user']])[0];
|
$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']]);
|
$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']]);
|
||||||
@ -19,7 +22,7 @@ if (is_empty($id)) {
|
|||||||
$database->insert($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number'], '#updated_at' => 'NOW()', '#created_at' => 'NOW()']);
|
$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 {
|
} else {
|
||||||
|
// Update an existing item by id
|
||||||
if ($from == 'assets') {
|
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]);
|
$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 {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user