X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=wwwroot%2Fbackend%2Fmysql%2Fbackend.inc;h=7b6537221a32c7fd731c9cc44d16163084aa2286;hb=a1e1fcead4644a1142a593aac616098415822336;hp=18b0d98c73debbdc474dd5c460c80ac313dac44a;hpb=3676f24250be4b7db303567eee89cd33247cf674;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index 18b0d98..7b65372 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -35,6 +35,35 @@ function update_nodes($user_id,$node_id,$referer_id) { } +function putNode($what,$where,$checkpermissions=true) { + global $db,$error,$error_messages; + $user_id = $_SESSION['user_id']; + if (!$user_id) { + $user_id=UBIK_ID; + } + if (!is_numeric($what) || !is_numeric($where)) { + $error=$error_messages['NUMERIC_NOT_NUMERIC']; + } + + $nodeshell = nodes::getNodeById($where,$user_id); + $nodeshell_vector = $nodeshell['node_vector']; + + if ($checkpermissions) { + $nodeshell_permissions = permissions::checkPermissions($nodeshell); + if (!$nodeshell_permissions['w']) { + $error = $error_messages['WRITE_PERMISSION_ERROR']; + return false; + } + } + + $dst_vector = $nodeshell_vector.str_pad($chosen,VECTOR_CHARS,0,STR_PAD_LEFT); + $q = "update neurons set synapse_created=NOW(),link='hard',synapse=synapse+1, dst_vector='$dst_vector' where src='$what' and dst='$where'"; + $result=$db->update($q); + + if (!$result) $db->query("insert into neurons set synapse_creator='$user_id',synapse_created=NOW(), src='$what',dst='$where',dst_vector='$dst_vector',link='hard',synapse=1"); + $db->query("update nodes set lastdescendant_created=NOW(),node_children_count=node_children_count+1 where node_id='$where'"); +} + function addNode($params) { global $db,$node,$error,$error_messages; $parent_id=$params['node_parent']; @@ -149,15 +178,17 @@ node_vector='".$params['node_vector']."'"; } } + function getNodeIdByName($name, $external_link=false) { + global $db; - function getNodeIdByName($name,$external_link=false) { - global $db; - $q="select node_id from nodes where node_name='$name'"; - if ($external_link) $q.=" and external_link='$external_link'"; - $set=$db->query($q); - $set->next(); - return $set->getString('node_id'); - } + $qh = sprintf('select node_id from nodes where node_name = "%s"', mysql_real_escape_string($name)); + if ($external_link) + $qh .= sprintf(' and external_link="%s"', mysql_real_escape_string($external_link)); + + $set = $db->query($qh); + $set->next(); + return $set->getString('node_id'); + } function getNodeById($node_handle,$user_id, $table_name="nodes") { global $db, $error; @@ -276,20 +307,20 @@ node_parent='$node_handle' order by node_created $orderby LIMIT $offset,$limit"; // Simple internal function to set node parrent -function setParent($params) { +function setParent($node_id,$parent_id) { global $db,$node,$error,$error_messages; - $parent_id=$params['node_parent']; - $node_id=$params['node_id']; if (!is_numeric($parent_id)) { return false; } - $q="select node_vector from nodes where node_id='$parent_id'"; - $parent_vector=$db->query($q); - $new_vector=$parent_vector.str_pad($node_id,VECTOR_CHARS,"0",STR_PAD_LEFT); - $q="update nodes set node_parent='$parent_id',node_vector='".$new_vector." - ' where node_id='$node_id'"; + $q="select node_vector from nodes where node_id='$parent_id'"; + $set=$db->query($q); + $set->next(); + $parent_vector=$set->getString('node_vector'); + $new_vector=$parent_vector.str_pad($node_id,VECTOR_CHARS,"0",STR_PAD_LEFT); + + $q="update nodes set node_parent='$parent_id',node_vector='$new_vector' where node_id='$node_id'"; $db->query($q); }