Permalink
Browse files

Keep track of saved results, so we know which we can safely delete

  • Loading branch information...
1 parent cdbbe79 commit 957b8bd0a8a332eadfa148ec93bab6d22549a3ea @NielsLeenheer NielsLeenheer committed Nov 29, 2013
Showing with 36 additions and 1 deletion.
  1. +18 −0 backend/index.php
  2. +12 −0 backend/models/results.php
  3. +2 −1 index.html
  4. +4 −0 scripts/base.js
View
@@ -99,6 +99,7 @@
SET
version = "' . mysql_real_escape_string($payload->version) . '",
revision = "' . mysql_real_escape_string($payload->revision) . '",
+ timestamp = NOW(),
ip = "' . mysql_real_escape_string(get_ip_address()) . '",
uniqueid = "' . mysql_real_escape_string($payload->uniqueid) . '",
score = "' . mysql_real_escape_string($payload->score) . '",
@@ -163,6 +164,23 @@
break;
+ case 'save':
+ $payload = json_decode($_REQUEST['payload']);
+
+ if (!$readonly) {
+ mysql_query('
+ UPDATE
+ results
+ SET
+ used = used + 1,
+ lastUsed = NOW()
+ WHERE
+ uniqueid = "' . mysql_real_escape_string($payload->uniqueid) . '"
+ ');
+ }
+
+ break;
+
case 'confirm':
$payload = json_decode($_REQUEST['payload']);
View
@@ -107,6 +107,18 @@ function getByUniqueId($id) {
");
if ($row = mysql_fetch_object($res)) {
+
+ // Update use counter
+ mysql_query('
+ UPDATE
+ results
+ SET
+ used = used + 1,
+ lastUsed = NOW()
+ WHERE
+ uniqueid = "' . mysql_real_escape_string($id) . '"
+ ');
+
return $row;
}
}
View
@@ -322,7 +322,8 @@ <h1 data-i18n><span>HTML<strong>5</strong>test</span> <em>how well does your bro
buttons.appendChild(button);
new Save(button, {
- id: r.uniqueid
+ id: r.uniqueid,
+ onSave: function() { submit('save', '{"uniqueid": "' + r.uniqueid + '"}'); }
});
var button = document.createElement('a');
View
@@ -377,6 +377,10 @@
"</p>" +
"<p>The unique id for this test is:<br><code>" + this.options.id + "</code></p>" +
"</div>";
+
+ if (this.options.onSave) {
+ this.options.onSave();
+ }
},
open: function(e) {

0 comments on commit 957b8bd

Please sign in to comment.