SnipeITAPI/getlocation.php

30 lines
728 B
PHP
Raw Normal View History

<?php
2016-05-19 00:41:51 -06:00
/**
* Get a list of all locations, and the location for a given id if any.
*/
require 'required.php';
//require 'dieifnotloggedin.php';
$from = $_GET['from'];
require 'readfrom.php';
$id = $_GET['id'];
2016-05-18 16:51:56 -06:00
if (is_empty($id) || $id == 0 || $id == null) {
$loc = '0';
} else {
2016-05-18 16:51:56 -06:00
if ($from == 'assets') {
$loc = $database->select($from, 'rtd_location_id', ['id' => $id])[0];
} else {
$loc = $database->select($from, 'location_id', ['id' => $id])[0];
}
2016-05-18 16:51:56 -06:00
if ($loc == null) {
$loc = 0;
}
}
$list = $database->select('locations', ['id', 'name']);
array_unshift($list, ['id' => "0", name => "None/Other"]);
2016-05-18 16:51:56 -06:00
die(json_encode(['status' => 'OK', 'location' => $loc, 'list' => $list]));