| 1 | <?php |
| 2 | |
| 3 | |
| 4 | function set_bookmark_category() { |
| 5 | global $node,$db,$error; |
| 6 | $bookmarks=$_POST['bookmarks_chosen']; |
| 7 | |
| 8 | if (isset($_POST['bookmark_category_id']) && |
| 9 | is_numeric($_POST['bookmark_category_id'])) { |
| 10 | $category_id=$_POST['bookmark_category_id']; |
| 11 | } |
| 12 | |
| 13 | $new_parent=nodes::getNodeById($category_id,$_SESSION['user_id']); |
| 14 | $new_parent_permissions=permissions::checkPermissions($new_parent); |
| 15 | |
| 16 | |
| 17 | if (!$new_parent_permissions['w']) { |
| 18 | global $error_messages; |
| 19 | $error=$error_messages['WRITE_PERMISSION_ERROR']; |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | |
| 24 | |
| 25 | foreach ($bookmarks as $chosen_id) { |
| 26 | |
| 27 | unset($chosen); |
| 28 | if (!is_numeric($chosen_id)) |
| 29 | { |
| 30 | $error=$error_messages['What a strange number..']; |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | $db->query("start transaction"); |
| 35 | |
| 36 | $q="update node_access set bookmark_category='$category_id' where node_id='$chosen_id' and user_id='".$_SESSION['user_id']."'"; |
| 37 | $db->query($q); |
| 38 | |
| 39 | $q="update neurons set dst='$category_id' where src='$chosen_id' and synapse_creator='".$_SESSION['user_id']."' and link='bookmark'"; |
| 40 | $result=$db->update($q); |
| 41 | if (!$result) $db->query("insert into neurons set synapse_creator='".$_SESSION['user_id']."',src='$chosen_id',dst='$category_id',link='bookmark'"); |
| 42 | $db->query("update nodes set lastdescendant_created=NOW() where node_id='$category_id'"); |
| 43 | $db->query("commit"); |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | ?> |
| 49 | |
| 50 | |