Re-post of Pay to Play code (insufficient funds warning)
Re-post of Pay to Play code (insufficient funds warning)
This code ensures that players must have the available funds in their account before they can save their picks.
-Spooky
Start with adding this function to common.asp
Next, open up weeklyEntry.asp and add this at the top along with the other #includes:
Now scroll down until you find the hasEntry section and add this code:
It should look something like this:
It should look something like this:
That should do it, just save the files and update your website. You might also need to clear your browser's cache if you aren't seeing the changes yet.
-Spooky
Start with adding this function to common.asp
Code: Select all
function GetAvailableFunds(username)
dim sql, rs
dim credits, fees
GetAvailableFunds = 0
'Get credits.
credits = 0
sql = "SELECT SUM(Amount) AS Total FROM Credits WHERE Username = '" & SqlEscape(username) & "'"
set rs = DbConn.Execute(sql)
if not rs.EOF then
credits = credits + rs.Fields("Total").Value
end if
if not IsNumeric(credits) then
credits = 0
end if
'Get fees.
fees = 0
'Count each weekly entry.
dim week, numWeeks
numWeeks = GetWeekCount()
for week = 1 to numWeeks
if InWeeklyPool(username, week) then
fees = fees + WEEKLY_ENTRY_FEE
end if
next
'Add the side pool entry (if used).
if InSidePool(username) then
fees = fees + SIDE_ENTRY_FEE
end if
GetAvailableFunds = credits - fees
end function
Code: Select all
<!-- #include file="includes/side.asp" -->
Code: Select all
'Get the user's available funds.
dim availFunds
availFunds = GetAvailableFunds(username)
if hasEntry then
availFunds = availFunds + WEEKLY_ENTRY_FEE
end if
Now, scroll down again until you come to the "Process an update request" section and add this code:'Determine if the user has an entry for the given week (so we can display
'the Delete button).
dim hasEntry
hasEntry = false
if username <> "" and InWeeklyPool(username, week) then
hasEntry = true
end if
'Get the user's available funds.
dim availFunds
availFunds = GetAvailableFunds(username)
if hasEntry then
availFunds = availFunds + WEEKLY_ENTRY_FEE
end if
Code: Select all
'If the player does not have sufficient funds, do not allow the picks
elseif not IsAdmin() and availFunds < WEEKLY_ENTRY_FEE then
call DisplayErrorMessage("Error: Your account does not have sufficient funds to make <br />these picks, Changes Not Accepted.")
'Process an update request.
elseif Request.Form("submit") = "Update" then
'Prevent entries by the Admin.
if username = ADMIN_USERNAME then
call DisplayErrorMessage("Error: User '" & ADMIN_USERNAME & "' may not make picks.")
'If the user is disabled, prevent the entry.
elseif IsDisabled() then
call DisplayErrorMessage("Error: Your account has been disabled, changes not accepted.<br />Please contact the Administrator.")
'If all games have been locked, prevent any updates (except by the Admin).
elseif not IsAdmin() and allLocked then
call DisplayErrorMessage("Error: All games for this week have been locked, changes not<br />accepted.")
'If the player does not have sufficient funds, do not allow the picks
elseif not IsAdmin() and availFunds < WEEKLY_ENTRY_FEE then
call DisplayErrorMessage("Error: Your account does not have sufficient funds to make <br />these picks, Changes Not Accepted.")
That should do it, just save the files and update your website. You might also need to clear your browser's cache if you aren't seeing the changes yet.