<%Option Explicit%>
	<!--#include file="mConstants.asp"-->
<HTML>
<HEAD>
<TITLE>Tournament Pyramid ladder - Place Challenge</TITLE>

<meta name="Microsoft Theme" content="nature 1001">
</HEAD>

<BODY>
<%
	'This is where we action the save of the challenge.
	dim challenge, rs, sql, d, new_match_id

	'this is were we actually save the details	
	challenge=request.querystring("challenge")

	If request.querystring("action")="s" then
		'this is were we actually save the challenge
		
		'The First thing to do is to add a new match record, to show the challenge details
		d = now 
		SQl="INSERT into matches (Pyramid_ID, Challenger_id, Challenged_id, Challenge_date, Cancelled) values (1," & chr(34) & session("userid") & chr(34) & "," & chr(34) & challenge & chr(34) & ",#" & d & "#, No);"
'response.write sql
		conn.execute sql
		
		' Now get the unique ID for this match and put into the user (pyramid) table to show a match is pending.
		set rs = server.CreateObject("adodb.recordset")
		rs.CursorLocation = 3
		sql="select * from matches where challenger_id=" & chr(34) & session("userid") & chr(34) & " and challenge_date=#"  & d & "#;"

'response.write sql
	    RS.Open sql, Conn, adOpenKeyset, AdLockReadOnly 
	    new_match_id = rs("match_id") 
		set rs= nothing
				
		'Then get the match ID thats created, and update the pending column for the position in the pyramid
		SQL="UPDATE users set pending=" & new_match_id & " where pyramid_id=1 and userid in ('" & challenge & "','" & session("userid") &"');"
'response.write sql
	    conn.execute sql
	    
	    'Now send user back to Pyramid view
	    response.redirect "default.asp"
	end if    
%>
			<table width="100%" height="131" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td valign="top" width="100%" bgcolor="#192d61" height="115">
					<table border="0" width="850" height="100%" cellpadding="0" cellspacing="0">
						<tr>
							<td valign="center" width=504 "height=90">
							<a href="default.asp">
							<IMG onclick="location.href ='default.asp'" height=111 src="giza%202.jpg" width=492 border=0 ></a>
							</td>
							<td valign="top" width=346 "height=90">
								<table border="0" width="346" height="101" cellpadding="0" cellspacing="0">
									  <tr>
										<td align="right" valign="bottom" height="20" width="96">
                                        <p align="left"><font color=white>&nbsp; User: </Font></td>	  
										<td align="right" valign="bottom" height="20" width="197">
                                        <u><font color=white><%=session("name")%></font></u></td>	  
									  </tr>
									  <tr>
						 				<td align="right" valign="center" height="20" width="96" >
                                        <p align="left"><FONT color=white>&nbsp; User ID: </FONT></td
										<td width="10">
						 				<td align="right" valign="center" height="20" width="197" >
                                        <u><FONT color=white> <%=session("userid")%> </FONT></u></td>
									  </tr>
									  <tr>
										<td align="right" height="20" width="96">
                                        <p align="left"><font color=white>&nbsp; Role: </Font></td>	  
										<td align="right" valign="bottom" height="20" width="197">
                                        <u><font color=white> <%=session("Role")%> </font></u></td>	  
									  </tr>
									  <tr>
										  <td align="right" valign="center" height="20" width="293" colspan="2">  
										  	<table border="0" width="283" height="100%" cellpadding="0" cellspacing="0">
												<tr>
                            						<A class=menu href="Logout.asp">
													<td width="277" bgcolor="#eab25f" align="middle" style="BORDER-RIGHT: #192d61 1px solid; BORDER-TOP: #192d61 1px solid; BORDER-LEFT: #192d61 1px solid; CURSOR: hand; BORDER-BOTTOM: #192d61 1px solid"><b>
                                                    Log out</b></td></a>
												</tr>
											</table>
										  </td>
									  </tr>
									  </table>
							 </td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td height="16" colspan="2" style="BORDER-RIGHT: #192d61 1px solid; BORDER-TOP: #192d61 1px solid; BORDER-LEFT: #192d61 1px solid; BORDER-BOTTOM: #192d61 1px solid" 
          bgcolor="#eab25f">&nbsp;</td>
				</tr>
			</table>

<%'This is the details about the challenge.. %>
<P> Please contact the person you want to challenge using the details below.</P>
<P> The challenge should be resolved (played or cancelled) within one month of 
the challenge being made.</P>
<P> You are making a challenge to :</P>
<div align="center">
  <center>

<%
	'Get the details of the challengee

	challenge=request.querystring("challenge")

	set rs = server.CreateObject("adodb.recordset")
	rs.CursorLocation = 3
	sql="select * from users where userid='" & challenge & "'"

    RS.Open sql, Conn, adOpenKeyset, AdLockReadOnly 
	
%>
  

<table border="0" cellpadding="0" cellspacing="0" style="border-color:#FFFFFF; border-collapse: collapse" width="547" id="AutoNumber1" bgcolor="#eab25f">
  <tr>
    <td width="114" align="center"><b>Name</b></td>
    <td width="430" colspan="2"><%=rs("Firstname") & " " & rs("Surname") %></td>
  </tr>
  <tr>
    <td width="114" align="center"><b>email</b></td>
    <td width="430" colspan="2"><%= "<a href=" & chr(34) & "mailto:" & rs("Email") & chr(34) & ">" & rs("email")%></td>
  </tr>
  <tr>
    <td width="114" align="center"><b>Phone</b></td>
    <td width="430" colspan="2"> <%=rs("Phone") %></td>
  </tr>
  <tr>
    <td width="114" align="center"><b>Playing days</b></td>
    <td width="430" colspan="2"><%=rs("playing_days") %></td>
  </tr>
  <tr>
    <td width="114" align="center"><b>Location</b></td>
    <td width="430" colspan="2"><%=rs("location") %></td>
  </tr>
  <tr>
    <td width="114" align="center">&nbsp;</td>
    <td width="430" colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td width="114" align="center">&nbsp;</td>
    <td width="215">
  	  <form method="post" action="challenge.asp?action=s&challenge=<%response.write challenge%>" name="form1">
      <p align="center">
      <input type="submit" value="Challenge" name="btnSubmit"></p>
      </form></td>
    <td width="215">  
      <form method="submit" action="default.asp" name="form2">
      <p align="center">
      <input type="submit" value="Cancel" name="btnCancel"> </p>
      </form></td>
  </tr>
</table>
  </center>
</div>
<%
	set rs=nothing
%>

</body>

</html>