]> git.sesse.net Git - remoteglot/blobdiff - www/manual-override.pl
Add an undo button to the admin interface.
[remoteglot] / www / manual-override.pl
index 13333524a91b7a78eea44e067e17a015bd5d0a7e..23f571f4c84105ef4dbd6a215ac296f2c60cf89c 100755 (executable)
@@ -20,14 +20,23 @@ if (!defined($password) || $password ne $remoteglotconf::adminpass) {
        exit;
 }
 
-$dbh->do('INSERT INTO game_extensions ( fen, history, player_w, player_b, ts, next_move ) VALUES ( ?, ?, ?, ?, CURRENT_TIMESTAMP, ? )',
-       undef,
-       Encode::decode_utf8($cgi->param('fen')),
-       Encode::decode_utf8($cgi->param('history')),
-       Encode::decode_utf8($cgi->param('player_w')),
-       Encode::decode_utf8($cgi->param('player_b')),
-       Encode::decode_utf8($cgi->param('move')));
-system("sudo", "touch", $remoteglotconf::target);
+if ($cgi->param('move') eq 'null') {
+       $dbh->do('DELETE FROM game_extensions WHERE fen=? AND history=? AND player_w=? AND player_b=?',
+               undef,
+               Encode::decode_utf8($cgi->param('fen')),
+               Encode::decode_utf8($cgi->param('history')),
+               Encode::decode_utf8($cgi->param('player_w')),
+               Encode::decode_utf8($cgi->param('player_b')));
+} else {
+       $dbh->do('INSERT INTO game_extensions ( fen, history, player_w, player_b, ts, next_move ) VALUES ( ?, ?, ?, ?, CURRENT_TIMESTAMP, ? )',
+               undef,
+               Encode::decode_utf8($cgi->param('fen')),
+               Encode::decode_utf8($cgi->param('history')),
+               Encode::decode_utf8($cgi->param('player_w')),
+               Encode::decode_utf8($cgi->param('player_b')),
+               Encode::decode_utf8($cgi->param('move')));
+}
+system("sudo", "/usr/bin/touch", $remoteglotconf::target);
 
 print CGI->header(-type=>'text/plain; charset=utf-8');
 print "OK\n";