Newer
Older
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
include_once("include/db.php");
# Return list of clients
function getAdminClients($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'clients.ID',
'Name' => 'clients.Name',
'AccessList' => 'clients.AccessList'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, AccessList FROM clients",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
# Loop through rows
$resultArray = array();
while ($row = $sth->fetchObject()) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['AccessList'] = $row->accesslist;
# Push this row onto array
array_push($resultArray,$item);
}
# Return results
return array($resultArray,$numResults);
}
# Return specific client row
function getAdminClient($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, AccessList FROM clients WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
return $res;
}
# Build array of results
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Name'] = $row->name;
$resultArray['AccessList'] = $row->accesslist;
# Return results
return $resultArray;
}
# Remove admin client
function removeAdminClient($params) {
# Begin transaction
DBBegin();
# Perform query
$res = DBDo("DELETE FROM client_attributes WHERE ClientID = ?",array($params[0]));
# Remove client from realms
if ($res !== FALSE) {
$res = DBDo("DELETE FROM clients_to_realms WHERE ClientID = ?",array($params[0]));
}
# Perform next query if successful
if ($res !== FALSE) {
$res = DBDo("DELETE FROM clients WHERE ID = ?",array($params[0]));
}
# Commit and return if successful
if (is_bool($res)) {
DBCommit();
return $res;
# Else rollback database
} else {
DBRollback();
}
return NULL;
}
# Add admin client
function createAdminClient($params) {
# Perform query
$res = DBDo("INSERT INTO clients (Name,AccessList) VALUES (?,?)",array($params[0]['Name'],$params[0]['AccessList']));
# Return result
if (is_bool($res)) {
return $res;
}
return NULL;
}
# Edit admin client
function updateAdminClient($params) {
# Perform query
$res = DBDo("UPDATE clients SET Name = ?, AccessList = ? WHERE ID = ?",
array($params[0]['Name'],$params[0]['AccessList'],$params[0]['ID']));
# Return result
if (is_bool($res)) {
return $res;
}
return NULL;
}
# vim: ts=4