get_image_link fix
[mirrors/Kyberia-bloodline.git] / wwwroot / inc / eventz / set_parent.inc
CommitLineData
51ff3226 1<?php
2function set_parent() {
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
40// echo 'Debug:: Novy vektor putu';
41// echo $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$set=$db->query("select * from neurons where dst='$chosen_id' and link='hard'");
56if ($set->getNumRows()>0){
57
58$q="update neurons set dst_vector='$new_vector.$src' where dst='$chosen_id' and link='hard'";
59$db->update($q);
60}
61
62
63
64$db->query("start transaction");
65$q="update nodes set node_parent='$new_parent_id',node_vector='".$new_vector."' where
66node_id='$chosen_id'";
67$db->query($q);
68$q="update nodes set
69node_vector=replace(node_vector,'".$chosen['node_vector']."','$new_vector') where
70node_vector like '".$chosen['node_vector']."%'";
71$changed=$db->update($q);
72$q="update nodes set node_children_count=node_children_count+1 where node_id='$new_parent_id'";
73$db->update($q);
74
75$db->query("commit");
76
77// echo '<br>debug:: pocet putov v node:: <br>';
78//
79// $set=$db->query("select * from neurons where dst='$chosen_id' and link='hard'");
80// echo $set->getNumRows();
81
82}
83return true;
84}
85?>
This page took 1.111951 seconds and 4 git commands to generate.