Browse Source

Allow entering scores manually (closes #5)

master
Fabian Kurz 3 months ago
parent
commit
1f496fc26d
  1. 38
      api.php
  2. 29
      functions.php
  3. 5
      help.php
  4. 64
      index.php
  5. 2
      login.php

38
api.php

@ -98,6 +98,9 @@
case 'list':
member_list();
break;
case 'update_manual_score':
update_manual_score();
break;
}
function upload($ign) {
@ -379,10 +382,17 @@
echo "Password must not be empty.";
return;
}
$value = "'".$value."'";
break;
case 'email':
$value = mysqli_real_escape_string($db, $o->value);
$_SESSION['email'] = $value;
$value = "'".$value."'";
break;
case 'manual':
error_log($o->value);
$value = $o->value ? 1 : 0;
$_SESSION['manual'] = $value;
break;
default:
echo "Invalid data.";
@ -390,7 +400,32 @@
break;
}
$q = mysqli_query($db, "update cwops_users set ".$o->item." = '".$value."' where id=".$_SESSION['id']);
$query = "update cwops_users set ".$o->item." = ".$value." where id=".$_SESSION['id'];
$q = mysqli_query($db, $query);
if ($q) {
echo "Updated.";
}
else {
echo "Data base error. Contact administrator if this persists.";
error_log(mysqli_error($db));
}
}
function update_manual_score () {
global $db;
$postdata = file_get_contents("php://input");
$o = json_decode($postdata);
if (! (in_array($o->item, array("aca", "cma", "was", "dxcc", "wae", "waz")) and is_int(0+$o->value))) {
echo "Invalid data.";
return;
}
$query = "update cwops_scores set ".$o->item." = ".$o->value." where uid=".$_SESSION['id'];
error_log($query);
$q = mysqli_query($db, $query);
if ($q) {
echo "Updated.";
}
@ -400,6 +435,7 @@
}
}
function award_pdf () {
$type = validate_get('type');
$callsign = $_SESSION['callsign'];

29
functions.php

@ -7,8 +7,35 @@ $call_exceptions = unserialize(file_get_contents("db/calls.phpserial"));
$arr_states = array("AK"=>1, "HI"=>1, "CT"=>1, "ME"=>1, "MA"=>1, "NH"=>1, "RI"=>1, "VT"=>1, "NJ"=>1, "NY"=>1, "DE"=>1, "MD"=>1, "PA"=>1, "AL"=>1, "FL"=>1, "GA"=>1, "KY"=>1, "NC"=>1, "SC"=>1, "TN"=>1, "VA"=>1, "AR"=>1, "LA"=>1, "MS"=>1, "NM"=>1, "OK"=>1, "TX"=>1, "CA"=>1, "AZ"=>1, "ID"=>1, "MT"=>1, "NV"=>1, "OR"=>1, "UT"=>1, "WA"=>1, "WY"=>1, "MI"=>1, "OH"=>1, "WV"=>1, "IL"=>1, "IN"=>1, "WI"=>1, "CO"=>1, "IA"=>1, "KS"=>1, "MN"=>1, "MO"=>1, "NE"=>1, "ND"=>1, "SD"=>1);
function stats($c) {
if ($_SESSION['manual']) {
stats_manual($c);
}
else {
stats_default($c);
}
}
function stats_manual($c) {
global $db;
$q = mysqli_query($db, "select aca, cma, was, dxcc, wae, waz from cwops_scores where uid=".$_SESSION['id']);
$r = mysqli_fetch_row($q);
?>
<h2>Statistics for <?=$_SESSION['callsign'];?></h2>
<table>
<tr><th>Award</th><th>Score</th><th>PDF</th></tr>
<tr><td>ACA</td> <td><input size="3" value="<?=$r[0];?>" id="acamanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=aca">Download PDF award</a></td></tr>
<tr><td>CMA</td> <td><input size="3" value="<?=$r[1];?>"id="cmamanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=cma">Download PDF award</a></td></tr>
<tr><td>WAS</td> <td><input size="3" value="<?=$r[2];?>" id="wasmanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=was">Download PDF award</a></td></tr>
<tr><td>DXCC</td><td><input size="3" value="<?=$r[3];?>" id="dxccmanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=dxcc">Download PDF award</a></td></tr>
<tr><td>WAE</td> <td><input size="3" value="<?=$r[4];?>" id="waemanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=wae">Download PDF award</a></td></tr>
<tr><td>WAZ</td> <td><input size="3" value="<?=$r[5];?>" id="wazmanual" onchange="update_manual(this.id);"></td> <td><a href="/api.php?action=award_pdf&type=waz">Download PDF award</a></td></tr>
</table>
<?
}
function stats_default($c) {
global $db;
global $wae_adif;

5
help.php

@ -17,7 +17,7 @@
<p>On the <a href="https://cwops.org/contact-us/awards/">CWops website</a>.</p>
<h2>How do I report my scores?</h2>
<p>Scores are automatically reported to the awards manager. There's nothing you need to do!</p>
<p>Scores are automatically reported to the awards manager. There's nothing you need to do, just upload your logs!</p>
<h2>Can I import my contacts from CAM?</h2>
<p>Yes, just upload the "yourcall.data" file from CAM instead of an ADIF file.</p>
@ -38,6 +38,9 @@
<h2>Can I upload multiple files at once?</h2>
<p>Yes, in the file open dialog, simply select more than one file by clicking on them while keeping the Ctrl key pressed.</p>
<h2>I am using another software to calculate my scores, how can I report them?</h2>
<p>In your account options check the box for manual score reporting. Then you'll get a form on which you can enter your raw numbers.</p>
<h2>Thanks</h2>
<p>Thanks to the following individuals for their help and contributions during the beta testing phase:</p>
<ul>

64
index.php

@ -20,12 +20,18 @@ if (array_key_exists("id", $_SESSION)) {
?>
<p>Logged in as <?=$_SESSION['callsign'];?>. <a href="/logout">Log out</a></p>
<?
if ($_SESSION['manual'] == 0) {
?>
<P>Upload new ADIF, CAM or Cabrillo log:
<input type="file" id="file" multiple /> <button id='upload' onClick='javascript:upload();'>Upload</button>
<input id="cbignore" type="checkbox" name="cbignore" value="1" checked> Take DXCC, WAZ and WAS values from the database (not from ADIF; recommended)
</p>
<div id="upload_result"></div>
<?
}
?>
<script>
function ol () {
@ -76,8 +82,11 @@ if (array_key_exists("id", $_SESSION)) {
for (var i = 0; i < items.length; i++) {
console.log(items[i]);
document.getElementById(items[i]).style.fontWeight = "normal";
document.getElementById(items[i] + "_div").style.display = "none";
try {
document.getElementById(items[i]).style.fontWeight = "normal";
document.getElementById(items[i] + "_div").style.display = "none";
}
catch {}
}
document.getElementById(item + "_div").style.display = "inline";
@ -256,13 +265,17 @@ if (array_key_exists("id", $_SESSION)) {
}
function update_account(item) {
var value = document.getElementById(item + '_field').value;
console.log('update account ' + item + ' => ' + value);
if (!value) {
alert("Value for " + item + " must not be empty!");
return;
if (item == 'manual') {
var value = document.getElementById(item + '_field').checked ? 1 : 0;
}
else {
var value = document.getElementById(item + '_field').value;
if (!value) {
alert("Value for " + item + " must not be empty!");
return;
}
}
console.log('update account ' + item + ' => ' + value);
var request = new XMLHttpRequest();
request.open("POST", '/api?action=update_account', true);
@ -291,15 +304,46 @@ if (array_key_exists("id", $_SESSION)) {
b.disabled = true;
}
}
function update_manual(i) {
var value = document.getElementById(i).value;
i = i.substr(0, i.length - "manual".length);
var request = new XMLHttpRequest();
request.open("POST", '/api?action=update_manual_score', true);
request.onreadystatechange = function() {
var done = 4, ok = 200;
if (request.readyState == done && request.status == ok) {
if (request.responseText) {
alert(request.responseText);
}
}
}
request.send(JSON.stringify({"item": i, "value": value}));
}
</script>
<br>
<?
# normal menu
if ($_SESSION['manual'] == 0) {
?>
<button id='stats' style="font-weight:bold" onClick="javascript:show(this.id);reload_stats();">Show Stats</button>
<button id='edit' onClick="javascript:show(this.id);">Edit QSOs</button>
<button id='log' onClick="javascript:show(this.id);">Enter QSOs</button>
<button id='uploads' onClick="javascript:show(this.id);reload_upload_history();">Show upload history</button>
<button id='account' onClick="javascript:show(this.id);reload_account();">Account</button>
<?
}
# menu for users who just enter their scores (manual mode), no uploads, etc.
else {
?>
<button id='stats' style="font-weight:bold" onClick="javascript:show(this.id);reload_stats();">Show Stats</button>
<button id='account' onClick="javascript:show(this.id);reload_account();">Account</button>
<?
}
?>
<br>
@ -358,6 +402,10 @@ If you like to start over (re-upload your whole log), you can delete all QSOs th
<tr><td>E-Mail:</td><td><input oninput="check_email();" id='email_field' name='email' type='text' size='15' value="<?=$_SESSION['email'];?>"></td><td><button id="setemail" onClick="javascript:update_account('email');">Save email address</button></td></tr>
</table>
<br>
<h3>Manual score reporting</h3>
<p>If you use a third party tool to calculate your CWops Award scores, you can disable the score calculation based on your log and enter the scores on a form.</p>
<input type="checkbox" name="manual" id="manual_field" onclick="update_account('manual');" <? if ($_SESSION['manual'] == 1) { echo "checked"; }?>> Enter scores manually (need to log off and on to take effect)
</div>
<div id="summary_div" style="display:none;">
</div>

2
login.php

@ -95,6 +95,7 @@ function recover () {
$_SESSION['id'] = $user->id;
$_SESSION['callsign'] = $user->callsign;
$_SESSION['email'] = $user->email;
$_SESSION['manual'] = $user->manual;
echo "Login successful! Forwarding...";
error_log("successful recovery of ".$user->callsign);
}
@ -141,6 +142,7 @@ function log_in_or_create ($call, $password, $recursive) {
$_SESSION['id'] = $user->id;
$_SESSION['callsign'] = $user->callsign;
$_SESSION['email'] = $user->email;
$_SESSION['manual'] = $user->manual;
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$token = sha1(random_bytes(64));

Loading…
Cancel
Save