| 1 | <?php |
| 2 | function put() { |
| 3 | global $error_messages,$db,$node,$error; |
| 4 | $user_id = $_SESSION['user_id']; |
| 5 | |
| 6 | if (!empty($_POST['nodeshell_id'])) $nodeshell_id = mysql_real_escape_string($_POST['nodeshell_id']); |
| 7 | else $nodeshell_id = mysql_real_escape_string($_POST['nodeshell_id_select']); |
| 8 | |
| 9 | $nodeshell = nodes::getNodeById($nodeshell_id,$_SESSION['user_id']); |
| 10 | $nodeshell_permissions = permissions::checkPermissions($nodeshell); |
| 11 | $nodeshell_vector = $nodeshell['node_vector']; |
| 12 | |
| 13 | if (!$nodeshell_permissions['w']) { |
| 14 | $error = $error_messages['WRITE_PERMISSION_ERROR']; |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | if (is_array($_POST['node_chosen'])) $put_array = $_POST['node_chosen']; |
| 19 | else $put_array[] = $node['node_id']; |
| 20 | |
| 21 | foreach ($put_array as $chosen) { |
| 22 | $dst_vector = $nodeshell_vector.str_pad($chosen,VECTOR_CHARS,0,STR_PAD_LEFT); |
| 23 | $q = "update neurons set synapse_created=NOW(),link='hard',synapse=synapse+1, |
| 24 | dst_vector='$dst_vector' where src='$chosen' and dst='$nodeshell_id'"; |
| 25 | $result=$db->update($q); |
| 26 | |
| 27 | if (!$result) $db->query("insert into neurons set synapse_creator='$user_id',synapse_created=NOW(), |
| 28 | src='$chosen',dst='$nodeshell_id',dst_vector='$dst_vector',link='hard',synapse=1"); |
| 29 | |
| 30 | $db->query("update nodes set lastdescendant_created=NOW() where node_id='$nodeshell_id'"); |
| 31 | } |
| 32 | } |
| 33 | ?> |