fixed "last" constant
[mirrors/Kyberia-bloodline.git] / trash / set_parent2.inc
... / ...
CommitLineData
1<?php
2function set_parent2() {
3// fixes put related bugs while reparenting >> that is fixes put dst vector
4global $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
12if (!$new_parent_permissions['w'] and !isHierarch($new_parent)) {
13global $error_messages;
14$error=$error_messages['WRITE_PERMISSION_ERROR'];
15return false;
16}
17
18$parent_vector=$new_parent['node_vector'];
19
20if (!is_array($nodes)) {
21$nodes[]=$node['node_id'];
22}
23
24if (($node['node_creator']!=$_SESSION['user_id']) and
25($node['node_permission']!='master') and !permissions::isHierarch($node)) {
26global $error_messages;
27$error=$error_messages['EVENT_PERMISSION_ERROR'];
28return false;
29}
30
31foreach ($nodes as $chosen_id) {
32unset($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
40echo 'Debug:: Novy vektor putu';
41echo $new_vector.$src;
42
43
44
45$chosen=nodes::getNodeById($chosen_id,$_SESSION['user_id']);
46
47if (($chosen['node_creator']!=$_SESSION['user_id']) and
48($chosen['node_permission']!='master') and !permissions::isHierarch($chosen)) {
49global $error_messages;
50$error=$error_messages['EVENT_PERMISSION_ERROR'];
51return false;
52}
53
54
55$db->query("start transaction");
56$q="update nodes set node_parent='$new_parent_id',node_vector='".$new_vector."' where
57node_id='$chosen_id'";
58$db->query($q);
59$q="update nodes set
60node_vector=replace(node_vector,'".$chosen['node_vector']."','$new_vector') where
61node_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'");
67if ($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
74echo '<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'");
78echo $set->getNumRows();
79
80}
81return false;
82}
83?>
This page took 0.108953 seconds and 4 git commands to generate.