-
Notifications
You must be signed in to change notification settings - Fork 42
/
permissions.php
144 lines (126 loc) · 4.98 KB
/
permissions.php
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Access Control Management
*
* Access permission administration functions
*
* @author Chinamann <[email protected]>
* @version $Id: permissions.php,v 2.4 2009/04/04 16:22:16 andig2 Exp $
*/
require_once './core/functions.php';
localnet_or_die();
permission_or_die(PERM_ADMIN);
/**
* Return if Checkbox is checked
*
* @param string $name Name of a checkbox
* @return boolean true if checked
*/
function getStateOfCheckbox($name)
{
global $$name;
return (!empty($$name));
}
/**
* input
*/
$id = req_int('id');
$diskid = req_string('diskid');
$from_uid = req_int('from_uid');
$save = req_int('save');
$message = req_string('message');
$permlist = [];
if (!empty($from_uid))
{
$WHERE = "";
if ($config['denyguest'])
{
$WHERE = ' WHERE A.id != '.$config['guestid'].
' AND C.id != '.$config['guestid'];
}
// current user permissions
$result = runSQL(
'SELECT
CASE WHEN B.permissions IS NULL THEN 1 ELSE 0 END AS newentry, '.
$from_uid.' AS from_uid,
C.name AS from_name,
A.id AS to_uid,
A.name AS to_name,
CASE WHEN B.permissions IS NULL THEN 0 ELSE B.permissions END AS permissions
FROM '.TBL_USERS.' A
LEFT OUTER JOIN '.TBL_PERMISSIONS.' B
ON A.id = B.TO_UID
AND B.FROM_UID = '. $from_uid .
' INNER JOIN '.TBL_USERS.' C ON '.$from_uid.' = C.ID' . $WHERE .
' ORDER BY A.id'
);
foreach ($result as $perm)
{
$perm['read'] = ($perm['permissions'] & PERM_READ);
$perm['write'] = ($perm['permissions'] & PERM_WRITE);
// process SAVE
if (!empty($save))
{
// make sure read is allowed when write is set
$rfn = 'readflag_'.$perm['to_uid'];
if (getStateOfCheckbox('writeflag_'.$perm['to_uid'])) $$rfn = '1';
// changed?
if ($perm['read'] != getStateOfCheckbox('readflag_'.$perm['to_uid']) ||
$perm['write'] != getStateOfCheckbox('writeflag_'.$perm['to_uid']))
{
// update
$newperm = PERM_READ * getStateOfCheckbox('readflag_'.$perm['to_uid']) +
PERM_WRITE * getStateOfCheckbox('writeflag_'.$perm['to_uid']);
$SQL = 'REPLACE INTO '.TBL_PERMISSIONS." SET from_uid=".$from_uid.", to_uid=".$perm['to_uid'].", permissions=".$newperm;
runSQL($SQL);
$perm['read'] = getStateOfCheckbox('readflag_'.$perm['to_uid']);
$perm['write'] = getStateOfCheckbox('writeflag_'.$perm['to_uid']);
/*
if ($perm['newentry']) // new
{
// insert
$newperm = PERM_READ * getStateOfCheckbox('readflag_'.$perm['to_uid']) +
PERM_WRITE * getStateOfCheckbox('writeflag_'.$perm['to_uid']);
$INSERT = 'INSERT INTO '.TBL_PERMISSIONS." SET from_uid=".$from_uid.", to_uid=".$perm['to_uid'].", permissions=".$newperm;
runSQL($INSERT);
$perm['read'] = getStateOfCheckbox('readflag_'.$perm['to_uid']);
$perm['write'] = getStateOfCheckbox('writeflag_'.$perm['to_uid']);
}
else // old
{
if ((getStateOfCheckbox('readflag_'.$perm['to_uid']) + getStateOfCheckbox('writeflag_'.$perm['to_uid'])) == 0)
{
// delete
$DELETE = "DELETE FROM ".TBL_PERMISSIONS." WHERE from_uid=".$from_uid." AND to_uid=".$perm['to_uid'];
runSQL($DELETE);
$perm['read'] = 0;
$perm['write'] = 0;
}
else
{
// update
$newperm = PERM_READ * getStateOfCheckbox('readflag_'.$perm['to_uid']) +
PERM_WRITE * getStateOfCheckbox('writeflag_'.$perm['to_uid']);
$UPDATE = "UPDATE ".TBL_PERMISSIONS." SET permissions=".$newperm." WHERE from_uid=".$from_uid." AND to_uid=".$perm['to_uid'];
runSQL($UPDATE);
$perm['read'] = getStateOfCheckbox('readflag_'.$perm['to_uid']);
$perm['write'] = getStateOfCheckbox('writeflag_'.$perm['to_uid']);
}
}
*/
}
// clear permission cache
clear_permission_cache();
}
$permlist[] = $perm;
}
}
// prepare templates
tpl_page();
$smarty->assign('permlist', $permlist);
//$smarty->assign('from_name', $permlist[0]['from_name']);
$smarty->assign('from_uid', $permlist[0]['from_uid']);
$smarty->assign('owners', out_owners(false,false,true));
$smarty->assign('message', $message);
// display templates
tpl_display('permissions.tpl');