function check_runner_in($cid, $rid, $device_id = "", $lat = "", $long = "", $timestamp = "") { $device_id = "some device"; $user_agent = $_SERVER['HTTP_USER_AGENT']; $ip_address = $_SERVER['REMOTE_ADDR']; $mysqli = connectdb(); $stmt = $mysqli->prepare("INSERT INTO " . CHECKINS_TBL . " (runner_id, checkpoint_id, device_id, user_agent, ip_address, lat, lng, checkin_time) VALUES (?,?,?,?,?,?,?,?)"); //print "INSERT INTO ".CHECKINS_TBL." (runner_id, checkpoint_id, device_id, user_agent, ip_address, lat, lng, checkin_time) VALUES ($rid,$cid,$device_id,$user_agent,$ip_address,$lat,$long,$timestamp)"; $stmt->bind_param('sissssss', $rid, $cid, $device_id, $user_agent, $ip_address, $lat, $long, $timestamp); $stmt->execute(); if ($stmt->affected_rows > 0) { $stmt->close(); _logger(LOG_CHECKIN, LOG_SUCCESS, $rid . " checked in to " . get_checkpoint_name($cid) . " " . $lat . "," . $long . " ts=" . $timestamp); return true; } else { $stmt->close(); if (is_already_checked_in($cid, $rid)) { _logger(LOG_CHECKIN, "", $rid . " is already checked in to " . get_checkpoint_name($cid)); } else { _logger(LOG_CHECKIN, LOG_FAILED, $rid . " failed to check in to " . get_checkpoint_name($cid) . " " . $lat . "," . $long); } return false; } }
exit; } if ($runner_id) { //print "Look here motherfuckers, we're checking you into a checkpoint. Good job<br /><br />"; print '<h2>Journey Log - Checkin<br>' . get_checkpoint_name($jlogCID) . '</h2> '; //print 'Going to try to check in runner '.$runner_id.'<br />'; //print $jlogCID.", ".$runner_id.",".$device_id.",".$lat.",".$long.",".$timestamp."<br />"; if (check_runner_in($jlogCID, $runner_id, $device_id, $lat, $long, $timestamp)) { print ' <p><strong><big>Runner ' . $runner_id . ' is checked in.</big></strong> <div style="font-size:14em;color:green;text-align: center;">✓</div> '; } else { //We should probably check and see if the runner's already been checked in and return a more descriptive message if (is_already_checked_in($jlogCID, $runner_id)) { print ' <p><strong><big>Runner ' . $runner_id . ' is already checked in.</big></strong> <div style="font-size:14em;color:green;text-align: center;">✓</div> '; } else { print ' <h3>Whoops, something went wrong. Runner ' . $runner_id . ' might already be checked in.</h3> <div style="font-size:14em;color:red;text-align: center;">?</div> '; } } } else { print "Runner id missing"; } ?>
function checkin($rid, $cid, $checked_in_earlier) { $mysqli = connectdb(); $stmt = $mysqli->prepare("INSERT INTO " . CHECKINS_TBL . " (runner_id, checkpoint_id, checked_in_earlier, checkin_time) VALUES (?,?,?,NOW())"); $stmt->bind_param('ssi', $rid, $cid, $checked_in_earlier); $stmt->execute(); if ($stmt->affected_rows > 0) { $stmt->close(); _logger(LOG_CHECKIN, LOG_SUCCESS, $rid . " checked in to " . get_checkpoint_name($cid)); # update the number of people checked in to this checkpoint so far $stmt = $mysqli->prepare("UPDATE " . CHECKPOINTS_TBL . " SET checked_in_so_far = checked_in_so_far+1 WHERE checkpoint_id = ?"); $stmt->bind_param('s', $cid); $stmt->execute(); $stmt->close(); # update the first checkin time $stmt = $mysqli->prepare("UPDATE " . CHECKPOINTS_TBL . " SET first_checkin_at = NOW(), first_runner=? WHERE first_checkin_at IS NULL AND checkpoint_id = ?"); $stmt->bind_param('ss', $rid, $cid); $stmt->execute(); $stmt->close(); # update the most recent checkin time $stmt = $mysqli->prepare("UPDATE " . CHECKPOINTS_TBL . " SET most_recent_checkin_at = NOW(), most_recent_runner=? WHERE checkpoint_id = ?"); $stmt->bind_param('ss', $rid, $cid); $stmt->execute(); $stmt->close(); return true; } else { if (is_already_checked_in($cid, $rid)) { _logger(LOG_CHECKIN, "", $rid . " is already checked in to " . get_checkpoint_name($cid)); $stmt->close(); return true; } else { _logger(LOG_CHECKIN, LOG_FAILED, $rid . " failed to check in to " . get_checkpoint_name($cid) . ": " . $stmt->error); $stmt->close(); return false; } } }