Commit | Line | Data |
---|---|---|
e586807d H |
1 | <?php |
2 | /* This program is free software. It comes without any warranty, to | |
3 | * the extent permitted by applicable law. You can redistribute it | |
4 | * and/or modify it under the terms of the Do What The Fuck You Want | |
5 | * To Public License, Version 2, as published by Sam Hocevar. See | |
6 | * http://sam.zoy.org/wtfpl/COPYING for more details. */ | |
7 | ||
8 | ||
9 | ||
10 | function set_parent() { | |
11 | ||
12 | global $node,$db,$error; | |
13 | $new_parent_id=$_POST['new_parent']; | |
14 | $nodes=$_POST['node_chosen']; | |
15 | $hierarch_id=$node['node_id']; | |
16 | ||
17 | $new_parent=nodes::getNodeById($new_parent_id,$_SESSION['user_id']); | |
18 | $new_parent_permissions=permissions::checkPermissions($new_parent); | |
19 | ||
20 | if (!$new_parent_permissions['w'] and !isHierarch($new_parent)) { | |
21 | global $error_messages; | |
22 | $error=$error_messages['WRITE_PERMISSION_ERROR']; | |
23 | return false; | |
24 | } | |
25 | ||
26 | $parent_vector=$new_parent['node_vector']; | |
27 | ||
28 | if (!is_array($nodes)) { | |
29 | $nodes[]=$node['node_id']; | |
30 | } | |
31 | ||
32 | if (($node['node_creator']!=$_SESSION['user_id']) and ($node['node_permission']!='master') and !permissions::isHierarch($node)) { | |
33 | global $error_messages; | |
34 | $error=$error_messages['EVENT_PERMISSION_ERROR']; | |
35 | return false; | |
36 | } | |
37 | ||
38 | foreach ($nodes as $chosen_id) { | |
39 | unset($chosen); | |
40 | ||
41 | $new_vector=$parent_vector.str_pad($chosen_id,VECTOR_CHARS,"0",STR_PAD_LEFT);; | |
42 | ||
43 | $chosen=nodes::getNodeById($chosen_id,$_SESSION['user_id']); | |
44 | ||
45 | if (($chosen['node_creator']!=$_SESSION['user_id']) and ($chosen['node_permission']!='master') and !permissions::isHierarch($chosen)) { | |
46 | global $error_messages; | |
47 | $error=$error_messages['EVENT_PERMISSION_ERROR']; | |
48 | return false; | |
49 | } | |
50 | ||
51 | ||
52 | $db->query("start transaction"); | |
53 | $q="update nodes set node_parent='$new_parent_id',node_vector='".$new_vector."' where node_id='$chosen_id'"; | |
54 | $db->query($q); | |
55 | $q="update nodes set node_vector=replace(node_vector,'".$chosen['node_vector']."','$new_vector') where node_vector like '".$chosen['node_vector']."%'"; | |
56 | $changed=$db->update($q); | |
57 | $q="update nodes set node_children_count=node_children_count+1 where node_id='$new_parent_id'"; | |
58 | $db->update($q); | |
59 | $db->query("commit"); | |
60 | ||
61 | } | |
62 | return true; | |
63 | } | |
64 | ?> |