MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mpermssagu.class
Ir para a documentação deste ficheiro.
1
<?php
41
class
MPermsSagu
extends
MPerms
42
{
43
private
$auth;
44
private
$module;
45
46
public
function
__construct
()
47
{
48
parent::__construct();
49
50
$this->module =
'admin'
;
51
52
$this->perms = array(
'A_ACCESS'
=> _M(
'Acesso/Visualização'
, $this->module),
53
'A_INSERT'
=> _M(
"Inseção"
, $this->module),
54
'A_DELETE'
=> _M(
"Exclusão"
, $this->module),
55
'A_UPDATE'
=> _M(
"Atualização"
, $this->module),
56
'A_EXECUTE'
=> _M(
"Execução"
, $this->module),
57
'A_ADMIN'
=> _M(
"Administrador"
, $this->module) );
58
59
$this->auth = $this->manager->GetAuth();
60
}
61
62
public
function
hasRights
($login, $transaction, $permToCheck)
63
{
64
$this->manager->loadMADConf();
65
66
$unidadeLogada =
null
;
67
68
if
( SAGU::getParameter(
'BASIC'
,
'ATIVAR_MULTIUNIDADE'
) == DB_TRUE )
69
{
70
$unidadeLogada = sMultiUnidade::obterObjetoUnidade();
71
}
72
73
$rights = $this->manager->getLogin()->GetRights();
74
if
( ($rights[$transaction] == $permToCheck || $rights[$transaction] == A_ADMIN) && is_array($unidadeLogada) && !count($unidadeLogada) > 0 )
75
{
76
return
true
;
77
}
78
79
$db = $this->manager->getDatabase($this->module);
80
81
$sql =
"SELECT COUNT(*)
82
FROM miolo_access a
83
INNER JOIN miolo_groupuser g
84
ON (g.idgroup = a.idgroup)
85
INNER JOIN miolo_user u
86
ON (u.iduser = g.iduser)
87
INNER JOIN miolo_transaction t
88
ON (t.idtransaction = a.idtransaction)
89
WHERE u.login = '$login'
90
AND lower(t.m_transaction) = lower('"
. $transaction .
"')
91
AND a.rights IN ("
. A_ADMIN .
', '
. $permToCheck .
')'
;
92
93
if
(is_array($unidadeLogada) && count($unidadeLogada) > 0 )
94
{
95
$sql .=
" AND g.unitid = $unidadeLogada->unitId "
;
96
}
97
98
$result = $db->query($sql);
99
100
return
($result[0][0] > 0);
101
}
102
112
public
function
addUserPerm
($uid, $pwd, $trans, $perm)
113
{
114
//Verifica se o usuário informado possui a permissão desejada
115
if
( ! $this->
checkUserAccess
($uid, $pwd, $trans, $perm) )
116
{
117
throw
new
Exception(_M(
"O usuário informado não possui as permissões necessárias."
, $module));
118
}
119
120
$login = $this->auth->getLogin();
121
$rigths = $login->GetRights();
122
$rigths[$trans] =
"$perm"
;
//Adicona permissão ao usuário logado
123
$login->SetRights($rigths);
124
$this->auth->setLogin($login);
125
return
true
;
126
}
127
137
public
function
removeUserPerm
($trans, $perm)
138
{
139
$login = $this->auth->getLogin();
140
$rigths = $login->GetRights();
141
unset($rigths[$trans]);
//Remove a permissão
142
$login->SetRights($rigths);
143
$this->auth->setLogin($login);
144
return
true
;
145
}
146
156
public
function
checkUserAccess
($uid, $pwd, $transaction, $perm)
157
{
158
$MIOLO
=
MIOLO::getInstance
();
159
$user =
$MIOLO
->GetBusinessMAD(
'user'
);
160
$user->GetByLoginPass($uid, $pwd);
161
162
$hasRights =
false
;
163
if
($user->login)
164
{
165
$login =
new
MLogin
($user);
166
$hasRights = $this->
hasRights
($login->id, $transaction, $perm);
167
}
168
else
169
{
170
throw
new
Exception(_M(
"Erro na identificação do usuário!"
, $module));
171
}
172
return
$hasRights;
173
}
174
175
public
function
checkAccess
($transaction, $perm, $deny =
false
, $group =
false
, $login =
false
)
176
{
177
$MIOLO
=
MIOLO::getInstance
();
178
$module = $this->module;
179
$action
=
MIOLO::getCurrentAction
();
180
181
$hasRights =
false
;
182
183
try
184
{
185
if
( !SAGU::isAllowedAction() )
186
{
187
if
( ! $this->auth->isLogged() )
188
{
189
throw
new
Exception(_M(
'Login não encontrado.'
, $module));
190
}
191
192
$login = is_object($login) ? $login : $this->auth->getLogin();
// MLogin object
193
$hasRights = $this->
hasRights
($login->id, $transaction, $perm);
194
195
if
( ! $hasRights )
196
{
197
throw
new
Exception(_M(
'Acesso negado'
, $module));
198
}
199
}
200
else
201
{
202
$hasRights =
true
;
203
}
204
}
205
catch
( Exception $e )
206
{
207
if
( $deny )
208
{
209
$transactionName = $this->
getTransactionName
($transaction);
210
211
$caption = _M(
'Acesso negado'
, $module);
212
$msg = $e->getMessage() .
"<br><br>\n"
.
213
'<i><font color=red>'
. _M(
'Transação'
, $module) .
": $transactionName ($transaction)<br>"
.
214
_M(
'Permissão necessária'
, $this->module) .
": "
. $this->perms[$perm] .
"</font></i><br><br>\n"
.
215
_M(
'Por favor, informe um usuário/senha válido para ter acesso a este conteúdo'
, $this->module) .
"<br>"
;
216
217
$go = $this->manager->history->Back(
'action'
);
218
$error =
Prompt::Error
($msg, $go, $caption,
''
);
219
$error->addButton( _M(
' Login '
), $this->manager->getActionURL($this->manager->getConf(
'login.module'
),
'logout'
,
null
,array(
'return_to'
=>urlencode(str_replace(
'&'
,
'&'
, $this->manager->history->Top())))),
''
);
220
221
$this->manager->Prompt($error,$deny);
222
}
223
}
224
225
return
$hasRights;
226
}
227
228
public
function
getRights
($login, $transaction =
null
)
229
{
230
$this->manager->loadMADConf();
231
$db = $this->manager->getDatabase($this->module);
232
233
$sql =
"SELECT a.rights
234
FROM miolo_access a
235
INNER JOIN miolo_groupuser g
236
ON (g.idgroup = a.idgroup)
237
INNER JOIN miolo_user u
238
ON (u.iduser = g.iduser)
239
INNER JOIN miolo_transaction t
240
ON (t.idtransaction = a.idtransaction)
241
WHERE u.login = '$login'
242
AND lower(t.m_transaction) = '"
. strtolower($transaction) .
"'"
;
243
244
$result = $db->query($sql);
245
246
$rights =
null
;
247
if
( count($result) > 0 )
248
{
249
foreach
( $result AS $index => $value )
250
{
251
$rights[] = $value[0];
252
}
253
}
254
255
return
$rights;
256
}
257
258
public
function
getTransactionName
($transaction)
259
{
260
$this->manager->loadMADConf();
261
$db = $this->manager->getDatabase($this->module);
262
263
$sql =
"SELECT A.nametransaction
264
FROM miolo_transaction A
265
WHERE lower(A.m_transaction) = '"
. strtolower($transaction) .
"'"
;
266
267
$result = $db->query($sql);
268
269
return
$result[0][0];
270
}
271
272
public
function
checkTransactionParents
($transaction, $perm)
273
{
274
275
}
276
}
277
?>
MIOLO\getCurrentAction
static getCurrentAction()
Definição
miolo.class:1086
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MLogin
Definição
mlogin.class:4
MPermsSagu
Definição
mpermssagu.class:42
MPermsSagu\__construct
__construct()
Definição
mpermssagu.class:46
MPermsSagu\addUserPerm
addUserPerm($uid, $pwd, $trans, $perm)
Definição
mpermssagu.class:112
MPermsSagu\hasRights
hasRights($login, $transaction, $permToCheck)
Definição
mpermssagu.class:62
MPermsSagu\checkAccess
checkAccess($transaction, $perm, $deny=false, $group=false, $login=false)
Definição
mpermssagu.class:175
MPermsSagu\getRights
getRights($login, $transaction=null)
Definição
mpermssagu.class:228
MPermsSagu\checkTransactionParents
checkTransactionParents($transaction, $perm)
Definição
mpermssagu.class:272
MPermsSagu\removeUserPerm
removeUserPerm($trans, $perm)
Definição
mpermssagu.class:137
MPermsSagu\getTransactionName
getTransactionName($transaction)
Definição
mpermssagu.class:258
MPermsSagu\checkUserAccess
checkUserAccess($uid, $pwd, $transaction, $perm)
Definição
mpermssagu.class:156
MPerms
Definição
mperms.class:3
MPrompt\Error
static Error($msg='', $goto='', $caption='', $event='')
Definição
mprompt.class:90
$MIOLO
$MIOLO
Definição
mdatetimefield.class:25
$action
$action
Definição
base.php:4
classes
security
mpermssagu.class
Gerado por
1.10.0