set_synapse_weight update
[mirrors/Kyberia-bloodline.git] / wwwroot / backend / mysql / backend.inc
index dd0c4f7cf82b6512973aa03e88a741dca6029364..ac554ed3691877192c2532a6175d4f2948c0c246 100644 (file)
@@ -343,16 +343,33 @@ function getKNeurons($user_id,$interval) {
 
 // Set synapse weight,
 
+// Secure
+// Returns true on sucess, otherwise false
+
 // XXX TODO
 
 function setSynapse($src,$dst,$weight) {
        global $db,$node,$error,$error_messages;
 
-       // XXX security fix
-//     $q="update neurons set synapse_weight='$synapse_weight' where dst = '$dst' and src = '$src'";
-//     $q="insert into neurons values('$synapse_weight','$dst','$src',NULL,'synapse',XXX,now(),XXX,$src)";
+       if ((!is_numeric($src)) or (!is_numeric($dst)) or (!is_numeric($weight))) {
+               return false;
+       }
+
+       // if already exists
+       $q="select src from neurons where dst ='$dst' and src = '$src'";
+       $set=$db->query($q);
 
-//     $set=$db->query($q);
+       $set->next();
+       $isrc=$set->getString('src');
+       if ( $set ) {
+               $q="update neurons set synapse_weight='$synapse_weight' 
+                       where dst = '$dst' and src = '$src'";
+       } else { 
+               // FIXME no vector set
+               $q="insert into neurons values('$synapse_weight','$dst','$src',0,'synapse',
+                                               CURRENT_TIMESTAMP(),now(),NULL,$src)";
+       }
+       $set=$db->query($q);
 
        return true;
 }
This page took 0.164689 seconds and 4 git commands to generate.