5 function isHierarch($node) {
8 if (IsSet($_SESSION['user_id'])) {
9 $user_id=$_SESSION['user_id'];
13 if (!$user_id) return false;
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);
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'";
20 $result=$db->query($q);
22 if ($result->getString('node_creator')==$user_id)
24 if ($result->getString('node_permission')=='master')
26 if ($result->getString('node_creator')=='operator')
28 // if ($user_id == 2045) // OMG
35 public static function checkPermissions($node) {
37 if (IsSet($_SESSION['user_id'])) {
38 $user_id=$_SESSION['user_id'];
44 thousand lights // OMGto Hierarchy!
45 (check&set procedure for giving permissions for non-public subnodes according
46 to bottom-top Hierarchy
48 if (($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);
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'";
54 $result=$db->query($q);
56 $hierarchy_bounce[]=$hierarch;
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']) {
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');
67 $q="update node_access set node_permission='".$result->getString('node_permission')."' where node_id='".$node['node_id']."' and user_id='".$user_id."'";
68 $updated=$db->update($q);
69 if (!$updated && IsSet($_SESSION['user_id'])) {
70 $q="insert into node_access set node_permission='".$result->getString('node_permission')."', node_id='".$node['node_id']."',user_id='".$user_id."'";
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';
80 $q="update node_access set node_permission='access' where node_id='".$node['node_id']."' and user_id='".$user_id."'";
81 $updated=$db->update($q);
82 if (!$updated && IsSet($_SESSION['user_id'])) {
83 $q="insert into node_access set node_permission='access', node_id='".$node['node_id']."',user_id='".$user_id."'";
96 //setting permissions for not logged in users
97 if ($user_id==$node['node_creator']) {
98 $permissions['r']=true;
99 $permissions['w']=true;
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;
112 $permissions['r']=false;
113 $permissions['w']=false;
117 //setting permissions for cube node
119 elseif ($node['node_system_access']=='cube') {
121 if (strpos($node['node_vector'],$_SESSION['cube_vector'])==true ) {
122 $permissions['r']=true;
123 $permissions['w']=true;
125 elseif (($node['node_permission']=='access')||($node['node_permission']=='op')||($node['node_permission']=='master')) {
126 $permissions['r']=true;
127 $permissions['w']=true;
132 $permissions['r']=false;
133 $permissions['w']=false;
138 //setting permissions for private node
139 elseif ($node['node_system_access']=='private') {
140 if (empty($node['node_permission'])) {
141 $permissions['r']=false;
142 $permissions['w']=false;
144 elseif ($node['node_permission']=='ban') {
145 $permissions['r']=false;
146 $permissions['w']=false;
149 elseif($node['node_permission']=='silence') {
150 $permissions['r']=true;
151 $permissions['w']=false;
155 $permissions['r']=true;
156 $permissions['w']=true;
160 //setting permissions for moderated node
161 elseif ($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;
166 elseif ($node['node_permission']=='ban') {
167 $permissions['r']=false;
168 $permissions['w']=false;
173 $permissions['r']=true;
174 $permissions['w']=false;
179 //setting rights for public node
180 elseif ($node['node_system_access']=='public') {
181 if ($node['node_permission']=='silence') {
182 $permissions['r']=true;
183 $permissions['w']=false;
186 elseif ($node['node_permission']=='ban') {
187 $permissions['r']=false;
188 $permissions['w']=false;
193 $permissions['r']=true;
194 $permissions['w']=true;
200 $permissions['r']=true;
201 $permissions['w']=true;