registration permission fix
[mirrors/Kyberia-bloodline.git] / trash / set_parent2.inc
1 <?php
2 function set_parent2() {
3 // fixes put related bugs while reparenting >> that is fixes put dst vector
4 global $node,$db,$error;
5 $new_parent_id=$_POST['new_parent'];
6 $nodes=$_POST['node_chosen'];
7 $hierarch_id=$node['node_id'];
8
9 $new_parent=nodes::getNodeById($new_parent_id,$_SESSION['user_id']);
10 $new_parent_permissions=permissions::checkPermissions($new_parent);
11
12 if (!$new_parent_permissions['w'] and !isHierarch($new_parent)) {
13 global $error_messages;
14 $error=$error_messages['WRITE_PERMISSION_ERROR'];
15 return false;
16 }
17
18 $parent_vector=$new_parent['node_vector'];
19
20 if (!is_array($nodes)) {
21 $nodes[]=$node['node_id'];
22 }
23
24 if (($node['node_creator']!=$_SESSION['user_id']) and
25 ($node['node_permission']!='master') and !permissions::isHierarch($node)) {
26 global $error_messages;
27 $error=$error_messages['EVENT_PERMISSION_ERROR'];
28 return false;
29 }
30
31 foreach ($nodes as $chosen_id) {
32 unset($chosen);
33
34 $new_vector=$parent_vector.str_pad($chosen_id,VECTOR_CHARS,"0",STR_PAD_LEFT);
35
36 $kset=$db->query("select src from neurons where dst='$chosen_id' and link='hard'");
37 $kset->next();$src=$kset->getString('src');
38
39
40 echo 'Debug:: Novy vektor putu';
41 echo $new_vector.$src;
42
43
44
45 $chosen=nodes::getNodeById($chosen_id,$_SESSION['user_id']);
46
47 if (($chosen['node_creator']!=$_SESSION['user_id']) and
48 ($chosen['node_permission']!='master') and !permissions::isHierarch($chosen)) {
49 global $error_messages;
50 $error=$error_messages['EVENT_PERMISSION_ERROR'];
51 return false;
52 }
53
54
55 $db->query("start transaction");
56 $q="update nodes set node_parent='$new_parent_id',node_vector='".$new_vector."' where
57 node_id='$chosen_id'";
58 $db->query($q);
59 $q="update nodes set
60 node_vector=replace(node_vector,'".$chosen['node_vector']."','$new_vector') where
61 node_vector like '".$chosen['node_vector']."%'";
62 $changed=$db->update($q);
63 $q="update nodes set node_children_count=node_children_count+1 where node_id='$new_parent_id'";
64 $db->update($q);
65
66 $set=$db->query("select * from neurons where dst='$chosen_id' and link='hard'");
67 if ($set->getNumRows()>0){
68
69 $q="update neurons set dst_vector='$new_vector.$src' where dst='$chosen_id' and link='hard'";
70 $db->update($q);
71 }
72 $db->query("commit");
73
74 echo '<br>debug:: pocet putov v node:: <br>';
75 // $q="update neurons set dst_vector='',link='soft',synapse_creator='$user_id' wheredst='$node_id' and src='$chosen' and link='hard'";
76
77 $set=$db->query("select * from neurons where dst='$chosen_id' and link='hard'");
78 echo $set->getNumRows();
79
80 }
81 return false;
82 }
83 ?>
This page took 0.401333 seconds and 4 git commands to generate.