X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=wwwroot%2Fbackend%2Fmysql%2Fbackend.inc;h=daba57b314d00aced86904a748ebd0d60c94d845;hb=78f1a5f44941de2459b71c375e36cf88227c689c;hp=a3ee375bd645043ceb6950fa60464bbbc13935a1;hpb=b7445c84b510c811e8ec6cec894b97ffbefeec5e;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index a3ee375..daba57b 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -68,11 +68,14 @@ function addNode($params) { global $db,$node,$error,$error_messages; $parent_id=$params['node_parent']; + if ($params['flag']=='registration') $params['node_creator']=UBIK_ID; + if (!is_numeric($parent_id)) { $parent_id=$node['node_id']; } $parent_permissions=permissions::checkPerms($parent_id); + if (!$parent_permissions['w']) { $error=$error_messages['WRITE_PERMISSION_ERROR']; logger::log('add','error','WRITE_PERMISSION_ERROR'); @@ -84,11 +87,8 @@ function addNode($params) { $kset->next(); $user_k=$kset->getString('user_k'); - if ($params['flag']=='registration') $params['node_creator']=UBIK_ID; - if (!$user_k && $params['node_creator']!=UBIK_ID) { $error=$error_messages['K_SPENT']; - return false; } @@ -181,9 +181,9 @@ function getUserByLogin($login) { static function getNodeIdByName($name, $external_link=false) { global $db; - $qh = sprintf('select node_id from nodes where node_name = "%s"', mysql_real_escape_string($name)); + $qh = sprintf('select node_id from nodes where node_name = "%s"', db_escape_string($name)); if ($external_link) - $qh .= sprintf(' and external_link="%s"', mysql_real_escape_string($external_link)); + $qh .= sprintf(' and external_link="%s"', db_escape_string($external_link)); $set = $db->query($qh); $set->next(); @@ -341,4 +341,77 @@ function getKNeurons($user_id,$interval) { return $k_array; } +// setSynapse + +// Set synapse weight. +// If synapse does not exists, create a new one. +// Secure. +// Returns true on sucess, otherwise false. + +function setSynapse($params){ + global $db,$node,$error,$error_messages; + + // security check + if ((!is_numeric($params['src'])) + or (!is_numeric($params['dst'])) + or (!is_numeric($params['weight']))) { + + return false; + } + + $src=$params['src']; + $dst=$params['dst']; + $weight=$params['weight']; + + // weight could be only positive + if ( $weight < 0) { + return false; + } + + // if already exists + $q="select count(src) from neurons where dst ='$dst' and src = '$src'"; + $set=$db->query($q); + $set->next(); + $isrc=$set->getString('count(src)'); + + if ( $isrc > 0 ) { + $q="update neurons set synapse_weight='$weight' + where dst = '$dst' and src = '$src'"; + } else { + // FIXME no vector set + $q="insert into neurons values('$weight','$dst','$src',0,'synapse', + CURRENT_TIMESTAMP(),now(),NULL,$src)"; + } + $set=$db->query($q); + + return true; +} + +// getSynapseWeight + +// If synapse does not exists, weight is 1 +// Secure. +// Returns synapse weight (from user to node) + +function getSynapseWeight($user_id,$node_id){ + global $db; + + if (!is_numeric($user_id)) + { return -1; } + if (!is_numeric($node_id)) + { return -1; } + + $set=$db->query("select synapse_weight from neurons where src =". + $user_id." and dst = ".$node_id." and link='synapse'"); + + $set->next(); + $synapse_weight=$set->getString('synapse_weight'); + + if (! ($synapse_weight) ) { $synapse_weight = 1;} + + return $synapse_weight; + } +} + +?>