Skip to content

Commit b2ed411

Browse files
committed
DBConnector: Use PSR-2 coding style
Signed-off-by: Stefan Weil <[email protected]>
1 parent b0b89f6 commit b2ed411

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

DBConnector.class.php

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
}
1212
$unittest[__FILE__] = (sizeof(get_included_files()) == 1);
1313

14-
function trace($text) {
14+
function trace($text)
15+
{
1516
error_log("palma: $text");
1617
}
1718

@@ -70,7 +71,8 @@ class DBConnector extends SQLite3
7071
// TODO: allow additional flags for constructor:
7172
// $flags = SQLITE3_OPEN_READWRITE|SQLITE3_OPEN_CREATE
7273
// $encryption_key
73-
public function __construct($filename = false) {
74+
public function __construct($filename = false)
75+
{
7476
if (!$filename) {
7577
$filename = dirname(__FILE__) . '/palma.db';
7678
}
@@ -84,16 +86,19 @@ public function __construct($filename = false) {
8486
$this->exec(self::SQL_CREATE_TABLES);
8587
}
8688

87-
public function resetTables() {
89+
public function resetTables()
90+
{
8891
$this->exec(self::SQL_RESET_TABLES . self::SQL_CREATE_TABLES);
8992
}
9093

91-
public function countWindows() {
94+
public function countWindows()
95+
{
9296
$numRows = $this->querySingle('SELECT count(*) FROM window WHERE state="active"');
9397
return $numRows;
9498
}
9599

96-
public function nextID() {
100+
public function nextID()
101+
{
97102
// Find the first unused monitor section and return its number.
98103
$quadrant_ids = array(1, 2, 3, 4);
99104
$window_db_ids = array();
@@ -116,19 +121,21 @@ public function nextID() {
116121
return $next;
117122
}
118123

119-
public function ipAddress() {
124+
public function ipAddress()
125+
{
120126
$ip = 'unknown';
121127
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
122128
// Server is hidden behind a proxy.
123129
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
124-
} else if (isset($_SERVER['REMOTE_ADDR'])) {
130+
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
125131
// Client has direct access to the server.
126132
$ip = $_SERVER['REMOTE_ADDR'];
127133
}
128134
return $ip;
129135
}
130136

131-
public function addUser($username, $address, $device = 'laptop') {
137+
public function addUser($username, $address, $device = 'laptop')
138+
{
132139
// Add a new user with his/her address and the device to the database.
133140
// TODO: Support more than one address for a given username.
134141
$this->exec("INSERT OR IGNORE INTO user VALUES (NULL, '$username', 1, 0)");
@@ -142,7 +149,8 @@ public function addUser($username, $address, $device = 'laptop') {
142149
}
143150
}
144151

145-
public function delUser($username, $address) {
152+
public function delUser($username, $address)
153+
{
146154
// Remove an existing user with his/her address from the database.
147155
// TODO: Support more than one address for a given username.
148156
$ip = $this->ipAddress();
@@ -159,14 +167,16 @@ public function delUser($username, $address) {
159167
}
160168
}
161169

162-
public function enableUser($username) {
170+
public function enableUser($username)
171+
{
163172
$state = $this->exec("UPDATE user SET enabled=1 WHERE name='$username'");
164173
if (!$state) {
165174
trace("enableUser($username) failed");
166175
}
167176
}
168177

169-
public function getUsers() {
178+
public function getUsers()
179+
{
170180
$users = array();
171181
$rows = $this->query("SELECT name FROM user");
172182
while ($row = $rows->fetchArray(SQLITE3_ASSOC)) {
@@ -176,7 +186,8 @@ public function getUsers() {
176186
return $users;
177187
}
178188

179-
public function getWindows() {
189+
public function getWindows()
190+
{
180191
// Get list of all windows, ordered by their section.
181192
$window_objs = array();
182193
$windows = @$this->query('SELECT * FROM window ORDER BY section ASC');
@@ -188,12 +199,14 @@ public function getWindows() {
188199
return $window_objs;
189200
}
190201

191-
public function getWindowIDBySection($section) {
202+
public function getWindowIDBySection($section)
203+
{
192204
$id = $this->querySingle("SELECT win_id FROM window WHERE section='$section'");
193205
return $id;
194206
}
195207

196-
public function getVNC_ClientInfo() {
208+
public function getVNC_ClientInfo()
209+
{
197210

198211
$info = array();
199212

@@ -218,16 +231,19 @@ public function getVNC_ClientWindowIDs() {
218231
}
219232
*/
220233

221-
public function getState_Window($window_id) {
234+
public function getState_Window($window_id)
235+
{
222236
$state = @$this->querySingle('SELECT state FROM window WHERE win_id="'.$window_id.'"');
223237
return $state;
224238
}
225239

226-
public function setState_Window($window_id, $state) {
240+
public function setState_Window($window_id, $state)
241+
{
227242
$this->exec('UPDATE window SET state="'.$state.'" WHERE win_id="'.$window_id.'"');
228243
}
229244

230-
public function insertWindow($window) {
245+
public function insertWindow($window)
246+
{
231247
// transfer ob complete window object/array necessary
232248
$sql = 'INSERT INTO window (id, win_id, section, state, file, handler, userid, date) ' .
233249
'VALUES ' . '("' .
@@ -239,7 +255,8 @@ public function insertWindow($window) {
239255
trace("sql=$sql, result=$new");
240256
}
241257

242-
public function deleteWindow($window_id) {
258+
public function deleteWindow($window_id)
259+
{
243260
$this->exec('DELETE FROM window WHERE win_id="'.$window_id.'"');
244261
}
245262

@@ -249,17 +266,19 @@ public function deleteVNCWindow($vnc_id) {
249266
}
250267
*/
251268

252-
public function deleteDebug($table, $id, $gt) {
269+
public function deleteDebug($table, $id, $gt)
270+
{
253271
$this->exec('DELETE FROM '.$table.' WHERE '.$id.' >"'.$gt.'"');
254272
}
255273

256-
public function updateWindow($window_id, $field, $value) {
274+
public function updateWindow($window_id, $field, $value)
275+
{
257276
$this->exec('UPDATE window SET '.$field.'="'.$value.'" WHERE win_id="'.$window_id.'"');
258277
}
259-
260278
}
261279

262-
function set_constants() {
280+
function set_constants()
281+
{
263282
// Get some constants from a configuration file.
264283

265284
$conf = parse_ini_file("palma.ini");
@@ -353,7 +372,8 @@ function set_constants() {
353372
print('CONFIG_THEME = ' . CONFIG_THEME . "\n");
354373
print('CONFIG_UPLOAD_DIR = ' . CONFIG_UPLOAD_DIR . "\n");
355374

356-
function dbModifiedCallback() {
375+
function dbModifiedCallback()
376+
{
357377
echo("Triggered callback\n");
358378
}
359379

0 commit comments

Comments
 (0)