summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.inc.php
blob: be202546e9bb9410705063cd10888877c028f013 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

HandleParameters();

function HandleParameters() {
	$getAction = $_GET['action'];

	if ($getAction == "roominfo") {
		$getRoomID = $_GET['id'];
		$getCoords = $_GET['coords'];

		if (empty($getCoords)) {
			$getCoords = '0';
		}
		getRoomInfoJson($getRoomID, $getCoords);
	}
}

function getRoomInfoJson($locationID, $coords) {
	$error = false;

	$dbquery = Database::simpleQuery("SELECT hidden FROM `locationinfo` WHERE locationid = $locationID");

	while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) {
		$hidden = $roominfo['hidden'];
		if ($hidden === '0') {
			$error = false;
		} else {
			$error = true;
		}
	}
	$pcs = getPcInfos($locationID, $coords);

	if (empty($pcs)) {
		$error = true;
	}

	if ($error === false) {
		echo $pcs;
	} else {
		echo "ERROR";
	}
}

function getPcInfos($locationID, $coords) {

	$dbquery;

	if ($coords === '1') {
		$dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = $locationID");
	} else {
		$dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = $locationID");
	}

	$pcs = array();

	while($pc=$dbquery->fetch(PDO::FETCH_ASSOC)) {

			$computer = array();

			$computer['id'] = $pc['machineuuid'];

			if ($coords === '1') {
				$position = json_decode($pc['position'], true);
				$computer['x'] = $position['gridRow'];
				$computer['y'] = $position['gridCol'];
			}

			$computer['inUse'] = 0;

			if ($pc['logintime'] > 0) {
				$computer['inUse'] = 1;
			}

			$pcs[] = $computer;
	}

	$str = json_encode($pcs, true);

	return $str;
}

?>