Commit | Line | Data |
---|---|---|
e586807d H |
1 | <?php |
2 | /* This program is free software. It comes without any warranty, to | |
3 | * the extent permitted by applicable law. You can redistribute it | |
4 | * and/or modify it under the terms of the Do What The Fuck You Want | |
5 | * To Public License, Version 2, as published by Sam Hocevar. See | |
6 | * http://sam.zoy.org/wtfpl/COPYING for more details. */ | |
7 | ||
8 | ||
9 | class permissions { | |
10 | ||
11 | function isHierarch($node) { | |
12 | ||
13 | global $db; | |
14 | $user_id=$_SESSION['user_id']; | |
15 | $hierarchy=explode(';',$node['node_vector']); | |
16 | foreach ($hierarchy as $hierarch) { | |
17 | $q="select nodes.node_creator,node_access.node_permission from nodes left join node_access on nodes.node_id=node_access.node_id and node_access.user_id='".$_SESSION['user_id']."' where nodes.node_id='$hierarch'"; | |
18 | $result=$db->query($q); | |
19 | $result->next(); | |
20 | if ($result->getString('node_creator')==$user_id) | |
21 | return true; | |
22 | if ($result->getString('node_permission')=='master') | |
23 | return true; | |
24 | if ($result->getString('node_creaotr')=='operator') | |
25 | return true; | |
26 | } | |
27 | return false; | |
28 | ||
29 | } | |
30 | ||
31 | function checkPermissions($node) { | |
32 | global $db; | |
33 | $user_id=$_SESSION['user_id']; | |
34 | ||
35 | //thousand lights to Hierarchy! | |
36 | if (($node['node_system_access']!='public' and $node['node_system_access']!='crypto') and empty($node['node_permission'])) { | |
37 | $hierarchy=array_reverse(explode(';',$node['node_vector'])); | |
38 | foreach ($hierarchy as $hierarch) { | |
39 | $q="select nodes.node_system_access,node_access.node_permission from nodes left join node_access on nodes.node_id=node_access.node_id and node_access.user_id='".$_SESSION['user_id']."' where nodes.node_id='$hierarch'"; | |
40 | $result=$db->query($q); | |
41 | $result->next(); | |
42 | $hierarchy_bounce[]=$hierarch; | |
43 | if ($result->getString('node_permission')!='') { | |
44 | array_pop($hierarchy_bounce); | |
45 | $node['node_permission']=$result->getString('node_permission'); | |
46 | foreach ($hierarchy_bounce as $hierarch_bounce) { | |
47 | $q="update node_access set node_permission='".$result->getString('node_permission')."' where node_id='$hierarch_bounce' and user_id='".$_SESSION['user_id']."'"; | |
48 | $updated=$db->update($q); | |
49 | if (!$updated) { | |
50 | $q="insert into node_access set node_permission='".$result->getString('node_permission')."', node_id='$hierarch_bounce',user_id='".$_SESSION['user_id']."'"; | |
51 | $db->query($q); | |
52 | } | |
53 | } | |
54 | break; | |
55 | } | |
56 | elseif ($result->getString('node_creator')=='$user_id') { | |
57 | array_pop($hierarchy_bounce); | |
58 | foreach ($hierarchy_bounce as $hierarch_bounce) { | |
59 | $q="update node_access set node_permission='access' where node_id='$hierarch_bounce' and user_id='".$_SESSION['user_id']."'"; | |
60 | $updated=$db->update($q); | |
61 | if (!$updated) { | |
62 | $q="insert into node_access set node_permission='access', node_id='$hierarch_bounce',user_id='".$_SESSION['user_id']."'"; | |
63 | $db->query($q); | |
64 | } | |
65 | } | |
66 | break; | |
67 | } | |
68 | elseif ($result->getString('node_system_access')=='public') { | |
69 | break; | |
70 | } | |
71 | } | |
72 | ||
73 | } | |
74 | ||
75 | ||
76 | //setting permissions for not logged in users | |
77 | if ($_SESSION['user_id']==$node['node_creator']) { | |
78 | $permissions['r']=true; | |
79 | $permissions['w']=true; | |
80 | } | |
81 | ||
82 | elseif (!$_SESSION['user_id']) { | |
83 | ||
84 | if ($node['node_external_access']=='yes' AND ($node['node_system_access']=='public' OR $node['node_system_access']=='moderated')) { | |
85 | $permissions['r']=true; | |
86 | $permissions['w']=false; | |
87 | ||
88 | } | |
89 | ||
90 | else { | |
91 | ||
92 | $permissions['r']=false; | |
93 | $permissions['w']=false; | |
94 | } | |
95 | } | |
96 | ||
97 | //setting permissions for personal node | |
98 | elseif ($node['node_system_access']=='personal') { | |
99 | ||
100 | if ($_SESSION['user_id']!=$node['node_creator']) { | |
101 | $permissions['r']=false; | |
102 | $permissions['w']=false; | |
103 | } | |
104 | else { | |
105 | $permissions['r']=true; | |
106 | $permissions['w']=true; | |
107 | } | |
108 | } | |
109 | ||
110 | //setting permissions for private node | |
111 | elseif ($node['node_system_access']=='private') { | |
112 | ||
113 | if (empty($node['node_permission'])) { | |
114 | $permissions['r']=false; | |
115 | $permissions['w']=false; | |
116 | } | |
117 | elseif($node['node_permission']=='silence') { | |
118 | $permissions['r']=true; | |
119 | $permissions['w']=false; | |
120 | } | |
121 | else { | |
122 | ||
123 | $permissions['r']=true; | |
124 | $permissions['w']=true; | |
125 | } | |
126 | } | |
127 | ||
128 | //setting permissions for moderated node | |
129 | elseif ($node['node_system_access']=='moderated') { | |
130 | if (($node['node_permission']=='access')||($node['node_permission']=='op')||($node['node_permission']=='master')) { | |
131 | $permissions['r']=true; | |
132 | $permissions['w']=true; | |
133 | } | |
134 | else { | |
135 | $permissions['r']=true; | |
136 | $permissions['w']=false; | |
137 | } | |
138 | } | |
139 | ||
140 | //setting rights for public node | |
141 | elseif ($node['node_system_access']=='public') { | |
142 | if ($node['node_permission']=='silence') { | |
143 | $permissions['r']=true; | |
144 | $permissions['w']=false; | |
145 | } | |
146 | ||
147 | elseif ($node['node_permission']=='ban') { | |
148 | $permissions['r']=false; | |
149 | $permissions['w']=false; | |
150 | } | |
151 | ||
152 | ||
153 | else { | |
154 | $permissions['r']=true; | |
155 | $permissions['w']=true; | |
156 | } | |
157 | } | |
158 | ||
159 | ||
160 | else { | |
161 | $permissions['r']=true; | |
162 | $permissions['w']=true; | |
163 | } | |
164 | ||
165 | return $permissions; | |
166 | } | |
167 | ||
168 | } | |
169 | ||
170 | ?> |