Trasovatelne templaty
[mirrors/Kyberia-bloodline.git] / trash / permissions.inc
CommitLineData
51ff3226 1<?php
2
3class permissions {
4
5function isHierarch($node) {
6
7 global $db;
8fce70c6 8 if (IsSet($_SESSION['user_id'])) {
9 $user_id=$_SESSION['user_id'];
10 } else {
11 $user_id=0;
12 }
51ff3226 13 if (!$user_id) return false;
8fce70c6 14
51ff3226 15 $node_vector=chunk_split($node['node_vector'],VECTOR_CHARS,';');
16 $hierarchy=explode(';',$node_vector);
17 foreach ($hierarchy as $hierarch) {
18 $hierarch=ltrim($hierarch,0);
8dabb29b 19 $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='".$user_id."' where nodes.node_id='$hierarch'";
51ff3226 20 $result=$db->query($q);
21 $result->next();
22 if ($result->getString('node_creator')==$user_id)
23 return true;
24 if ($result->getString('node_permission')=='master')
25 return true;
26 if ($result->getString('node_creator')=='operator')
27 return true;
8dabb29b 28// if ($user_id == 2045) // OMG
29// return true;
51ff3226 30 }
31 return false;
32
33}
34
fee499b9 35public static function checkPermissions($node) {
51ff3226 36global $db;
0338f511 37if (IsSet($_SESSION['user_id'])) {
808a489e 38 $user_id=$_SESSION['user_id'];
d9464c68 39} else {
40 $user_id=0;
808a489e 41}
51ff3226 42
43/*
8dabb29b 44thousand lights // OMGto Hierarchy!
51ff3226 45(check&set procedure for giving permissions for non-public subnodes according
46to bottom-top Hierarchy
47*/
48if (($node['node_system_access']!='public' and $node['node_system_access']!='crypto') and empty($node['node_permission'])) {
49 $node_vector=trim(chunk_split($node['node_vector'],VECTOR_CHARS,';'),';');
50 $hierarchy=array_reverse(explode(';',$node_vector));
51 foreach ($hierarchy as $hierarch) {
52 $hierarch=ltrim($hierarch,0);
8dabb29b 53 $q="select nodes.node_creator,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='".$user_id."' where nodes.node_id='$hierarch'";
51ff3226 54 $result=$db->query($q);
55 $result->next();
56 $hierarchy_bounce[]=$hierarch;
57
58 //if hierarch permission rights are different than that of the node, quit the process changing nothing
59 if ($result->getString('node_system_access')!=$node['node_system_access']) {
60 break;
61 }
62
63 //if hierarch node_user relation exist, set it for node also
64 elseif ($result->getString('node_permission')!='') {
65 array_pop($hierarchy_bounce);
66 $node['node_permission']=$result->getString('node_permission');
07d8a19c 67 $q="update node_access set node_permission='".$result->getString('node_permission')."' where node_id='".$node['node_id']."' and user_id='".$user_id."'";
51ff3226 68 $updated=$db->update($q);
69 if (!$updated && IsSet($_SESSION['user_id'])) {
07d8a19c 70 $q="insert into node_access set node_permission='".$result->getString('node_permission')."', node_id='".$node['node_id']."',user_id='".$user_id."'";
51ff3226 71 $db->query($q);
72 }
73 break;
74 }
75
76 //similiar.if user is creator of hierarch, give him access
77 elseif ($result->getString('node_creator')==$user_id) {
78 array_pop($hierarchy_bounce);
79 $node['node_permission']='access';
07d8a19c 80 $q="update node_access set node_permission='access' where node_id='".$node['node_id']."' and user_id='".$user_id."'";
51ff3226 81 $updated=$db->update($q);
82 if (!$updated && IsSet($_SESSION['user_id'])) {
07d8a19c 83 $q="insert into node_access set node_permission='access', node_id='".$node['node_id']."',user_id='".$user_id."'";
51ff3226 84 $db->query($q);
85 }
86 break;
87 }
88
89
90
91 }
92
93}
94
95
96//setting permissions for not logged in users
07d8a19c 97if ($user_id==$node['node_creator']) {
98 $permissions['r']=true;
99 $permissions['w']=true;
51ff3226 100}
101
07d8a19c 102elseif (!$user_id) {
51ff3226 103
104 if ($node['node_external_access']=='yes' AND ($node['node_system_access']=='public' OR $node['node_system_access']=='moderated' OR $node['node_system_access']=='cube')) {
105 $permissions['r']=true;
106 $permissions['w']=false;
107
108 }
109
110 else {
111
112 $permissions['r']=false;
113 $permissions['w']=false;
114 }
115}
116
117//setting permissions for cube node
118
119elseif ($node['node_system_access']=='cube') {
120
121 if (strpos($node['node_vector'],$_SESSION['cube_vector'])==true ) {
122 $permissions['r']=true;
123 $permissions['w']=true;
124 }
125 elseif (($node['node_permission']=='access')||($node['node_permission']=='op')||($node['node_permission']=='master')) {
126 $permissions['r']=true;
127 $permissions['w']=true;
128 }
129
130
131 else {
132 $permissions['r']=false;
133 $permissions['w']=false;
134 }
135}
136
137
138//setting permissions for private node
139elseif ($node['node_system_access']=='private') {
140 if (empty($node['node_permission'])) {
141 $permissions['r']=false;
142 $permissions['w']=false;
143 }
144 elseif ($node['node_permission']=='ban') {
145 $permissions['r']=false;
146 $permissions['w']=false;
147 }
148
149 elseif($node['node_permission']=='silence') {
150 $permissions['r']=true;
151 $permissions['w']=false;
152 }
153 else {
154
155 $permissions['r']=true;
156 $permissions['w']=true;
157 }
158}
159
160//setting permissions for moderated node
161elseif ($node['node_system_access']=='moderated') {
162 if (($node['node_permission']=='access')||($node['node_permission']=='op')||($node['node_permission']=='master')) {
163 $permissions['r']=true;
164 $permissions['w']=true;
165 }
166 elseif ($node['node_permission']=='ban') {
167 $permissions['r']=false;
168 $permissions['w']=false;
169 }
170
171
172 else {
173 $permissions['r']=true;
174 $permissions['w']=false;
175 }
176
177}
178
179//setting rights for public node
180elseif ($node['node_system_access']=='public') {
181 if ($node['node_permission']=='silence') {
182 $permissions['r']=true;
183 $permissions['w']=false;
184 }
185
186 elseif ($node['node_permission']=='ban') {
187 $permissions['r']=false;
188 $permissions['w']=false;
189 }
190
191
192 else {
193 $permissions['r']=true;
194 $permissions['w']=true;
195 }
196}
197
198
199else {
200 $permissions['r']=true;
201 $permissions['w']=true;
202}
203return $permissions;
204}
205
206}
207
208?>
This page took 1.05062 seconds and 4 git commands to generate.