1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Base/Model.php');
|
---|
4 |
|
---|
5 | class Permission extends Model
|
---|
6 | {
|
---|
7 | function LoadForUser($User)
|
---|
8 | {
|
---|
9 | $Result = array();
|
---|
10 | $DbResult = $this->Database->query('SELECT * FROM `PermissionAssignment` WHERE `User`='.$User);
|
---|
11 | while($DbRow = $DbResult->fetch_assoc())
|
---|
12 | {
|
---|
13 | if($DbRow['SubGroup'] > 0) $Result = array_merge($Result, $this->LoadForGroup($DbRow['SubGroup']));
|
---|
14 | if($DbRow['Operation'] > 0)
|
---|
15 | {
|
---|
16 | $DbResult2 = $this->Database->query('SELECT `PermissionOperation`.*, `Module`.`Name` FROM `PermissionOperation` JOIN `Module` ON `Module`.`Id` = `PermissionOperation`.`Module` WHERE `PermissionOperation`.`Id`='.$DbRow['Operation']);
|
---|
17 | $DbRow2 = $DbResult2->fetch_assoc();
|
---|
18 | $Result[$DbRow2['Name']][$DbRow2['Action']][$DbRow2['Item']] = true;
|
---|
19 | }
|
---|
20 | }
|
---|
21 | $this->Data = $Result;
|
---|
22 | }
|
---|
23 |
|
---|
24 | function LoadForGroup($Group)
|
---|
25 | {
|
---|
26 | $Result = array();
|
---|
27 | $DbResult = $this->Database->query('SELECT * FROM `PermissionAssignment` WHERE `Group`='.$Group);
|
---|
28 | while($DbRow = $DbResult->fetch_assoc())
|
---|
29 | {
|
---|
30 | if($DbRow['SubGroup'] > 0) $Result = array_merge($Result, $this->LoadForGroup($DbRow['SubGroup']));
|
---|
31 | if($DbRow['Operation'] > 0)
|
---|
32 | {
|
---|
33 | $DbResult2 = $this->Database->query('SELECT `PermissionOperation`.*, `Module`.`Name` FROM `PermissionOperation` JOIN `Module` ON `Module`.`Id` = `PermissionOperation`.`Module` WHERE `PermissionOperation`.`Id`='.$DbRow['Operation']);
|
---|
34 | $DbRow2 = $DbResult2->fetch_assoc();
|
---|
35 | $Result[$DbRow2['Name']][$DbRow2['Action']][$DbRow2['Item']] = true;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | return($Result);
|
---|
39 | }
|
---|
40 |
|
---|
41 | function Check($Module, $Action, $Item = 0)
|
---|
42 | {
|
---|
43 | if(array_key_exists($Module, $this->Data) and array_key_exists($Action, $this->Data[$Module]) and array_key_exists($Item, $this->Data[$Module][$Action])) $Result = true;
|
---|
44 | else $Result = false;
|
---|
45 | return($Result);
|
---|
46 | }
|
---|
47 | }
|
---|