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
|
<?php
class SubPage
{
public static function doPreprocess()
{
$action = Request::post('action', '', 'string');
if ($action === 'delete') {
User::assertPermission('networkshares.save');
$shareid = Request::post('shareid', false, 'int');
if ($shareid) {
$res = Database::exec('DELETE FROM sat.presetnetworkshare WHERE shareid = :shareid', ['shareid' => $shareid]);
if ($res) Message::addSuccess('networkshare-deleted');
}
} else if ($action === 'save') {
User::assertPermission('networkshares.save');
$shareid = Request::post('shareid', false, 'int');
$sharename = Request::post('sharename', false, 'string');
$path = Request::post('path', false, 'string');
$target = Request::post('target', null, 'string');
$username = Request::post('username', null, 'string');
$password = Request::post('password', null, 'string');
if ($sharename && $path) {
if ($shareid) {
Database::exec('UPDATE sat.presetnetworkshare SET sharename = :sharename, path = :path, target = :target, username = :username, password = :password'
.' WHERE shareid = :shareid', compact('shareid', 'sharename', 'path', 'target', 'username', 'password'));
} else {
Database::exec('INSERT INTO sat.presetnetworkshare (sharename, path, target, username, password, active)'
.' VALUES (:sharename, :path, :target, :username, :password, 0)', compact('sharename', 'path', 'target', 'username', 'password'));
}
Message::addSuccess('networkshare-saved');
}
} else if ($action === 'toggleActive') {
User::assertPermission('networkshares.save');
$shareid = Request::post('shareid', false, 'int');
Database::exec('UPDATE sat.presetnetworkshare SET active = !active WHERE shareid = :shareid', compact('shareid'));
}
User::assertPermission('networkshares.view');
}
public static function doRender()
{
$show = Request::get('show', 'list', 'string');
if ($show === 'list') {
$res = Database::simpleQuery('SELECT * FROM sat.presetnetworkshare;');
$rows = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$row['specificUser'] = $row['username'] && $row['password'];
$rows[] = $row;
}
Render::addTemplate('networkshares', ['networkshares' => $rows, 'hasEditPermissions' => User::hasPermission('networkshares.save')]);
} else if ($show === 'edit') {
$shareid = Request::get('shareid', 0, 'int');
$data = Database::queryFirst('SELECT * FROM sat.presetnetworkshare WHERE shareid = :shareid', ['shareid' => $shareid]);
if ($data['username'] && $data['password']) $data['specificUser'] = 'selected';
else $data['loggedInUser'] = 'selected';
Render::addTemplate('networkshares-edit', $data);
}
}
}
|