On Error Resume Next
Dim strConn,Conn,RecObj,strSQL,currentStatus,strStatus,arrSubject(1),blnApproved
Dim intCount,strDate : intCount = 0
Dim arrCoachPics(4)
Dim arrCoachEmail(4)
Dim arrCoachName(4)
Dim arrCoachPhone(4)

Const Appending=8

'***EMAIL CONSTANT
Const cdoContentDisposition = "urn:schemas:mailheader:content-disposition"
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort   = 2
Const cdoSMTPServer      = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort  = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout  = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate =	"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"		
Const EMAIL_FORM = "donotreply@sportsmgr.us"



strConn = "Provider=SQLOLEDB;Data Source=WIN-59JDF64IOMC;Initial Catalog=cloudspo_sportsmgr;User Id=cloudspo_sports;password=letmein@cliff64"
strSQL = "EXECUTE dbo.USP_ROSTER_NOTICES"
Set Conn = CreateObject("adodb.Connection")
With Conn
.ConnectionString  = strConn 
.Open 
End With





Set RecObj = CreateObject("adodb.recordset")
With RecObj
.Open strSQL,Conn
Do While .EOF = False
For I=1 To 4
arrCoachPics(I) = ""  : arrCoachEmail(I) = "" : arrCoachName(I) = "" : arrCoachPhone(I) = ""
Next


If .Fields("PlayerCount") <= .Fields("RosterCountP") And .Fields("CoachCount") <= .Fields("RosterCountC") Then
	currentStatus = 1
Else
	currentStatus = 2
End If 
If .Fields("RosterStatus") <> currentStatus Or IsNull(.Fields("NoticeDate")) = True Then
If currentStatus = 1 Then 'Team Approved
blnApproved = "T"
strDate = .Fields("LastAppUpdate")
arrSubject(0) = "Congrats!: "&.Fields("SMOrg") & "-" & .Fields("TeamName") & " has been approved by "&.Fields("NameAbbr")&" for "&.Fields("Season")
arrSubject(1) = .Fields("SMOrg")&"-"&.Fields("Season")&"-"&.Fields("League")&"-"&.Fields("TeamName")&" is approved by "&.Fields("NameAbbr")
Call SendEmail(.Fields("TeamID"),blnApproved,.Fields("FormAbbr"),.Fields("SMOrgID"),.Fields("Approved"),.Fields("Disapproved"))
Else
blnApproved = "F"
arrSubject(0) = "Note: "&.Fields("SMOrg") & "-" & .Fields("TeamName") & " is no longer approved by "&.Fields("NameAbbr")&" for "&.Fields("Season")
arrSubject(1) = .Fields("SMOrg")&"-"&.Fields("Season")&"-"&.Fields("League")&"-"&.Fields("TeamName")&" is no longer approved by "& .Fields("NameAbbr")
Call SendEmail(.Fields("TeamID"),blnApproved,.Fields("FormAbbr"),.Fields("SMOrgID"),.Fields("Approved"),.Fields("Disapproved"))
End If
strSQL= "UPDATE TeamNames SET RosterStatus="&currentStatus&",NoticeDate=GETDATE() WHERE TeamID="&.Fields("TeamID")
Conn.Execute(strSQL)
Else
strSQL= "UPDATE TeamNames SET RosterStatus="&currentStatus&" WHERE TeamID="&.Fields("TeamID")
Conn.Execute(strSQL)
End If 
.MoveNext
Loop
End With

'RecObj.Close() : Set RecObj = Nothing 

'strAttachment = PdfHtmlWithPicture(127683,"MAYSL",455) 
'Call SendEmail(127683,"T","MAYSL-PICS",455,"T","F")
Conn.Close() : Set Conn = Nothing

Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile("C:\ScheduleTask\rosterLog.txt", Appending) 
f.Write VBCRLF&intCount&" Emails Sent Sucessfully At "&Now&VBCRLF&"------------------"
f.close()
Set fs=Nothing




Sub SendEmail(ByVal Team,ByVal bln,ByVal FormAbbr,ByVal OrgID,ByVal blnNoticeApproved,ByVal blnNoticeDisApproved)
Dim objMail,strSubject,RecMail,strCoachPlayer,strBody
If bln="F" Then  
strCoachPlayer = PlayerCaoch(Team)
Else
If UCase(FormAbbr) <> "MAYSL-PICS"  Then 
strAttachment=PdfHtml(Team,FormAbbr)
ElseIf UCase(FormAbbr) = "MYSL-PICS" Then
strAttachment=PdfHtmlWithPicture(Team,"MYSL",OrgID) 
ElseIf UCase(FormAbbr) = "MAYSL-PICS" Then
strAttachment=PdfHtmlWithPicture(Team,"MAYSL",OrgID) 
End If 
End If
Set RecMail =CreateObject("adodb.recordset")
With RecMail
.Open "EXECUTE USP_COACH_APPROVER "&Team & "," & OrgID,Conn
Do While .EOF =False
If .Fields("RosterNotice") = 3 Then '***If Approver has both approved and disapproved
intCount= intCount + 1

'***SEND EMAIL
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
	.Item(cdoSendUsingMethod)       = cdoSendUsingPort
	.Item(cdoSMTPServer)            = "mail.sportsmgr.us"
	.Item(cdoSMTPServerPort)        = 25
	.Item(cdoSMTPAuthenticate)      = cdoBasic
	.Item(cdoSendUserName)          = "donotreply@sportsmgr.us"
	.Item(cdoSendPassword)         = "Shadow@1958"
	.Item(cdoSMTPConnectionTimeout) = 10
	.Update
End With
Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration = objConfig

With objMail
.Subject=arrSubject(RecMail.Fields(2))
.From="SportsManager<donotreply@sportsmanager.us>"
.To=RecMail.Fields(1)
'.BCC = "Copy<copy@sportsmanager.us>;bhartiya.ravi@gmail.com"
If bln = "T" Then
	objMail.AddAttachment strAttachment
End If
.HTMLBody = strCoachPlayer
.Send
End With
Set objMail=Nothing
ElseIf .Fields("Type") = 1 And ((bln="T" And .Fields("RosterNotice")=1) Or (bln="F" And .Fields("RosterNotice")=2)) Then '**IF APPROVER HAS EITHER APPROVED OR DISAPPROVED
intCount= intCount + 1

'***SEND EMAIL
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
	.Item(cdoSendUsingMethod)       = cdoSendUsingPort
	.Item(cdoSMTPServer)            = "mail.sportsmgr.us"
	.Item(cdoSMTPServerPort)        = 25
	.Item(cdoSMTPAuthenticate)      = cdoBasic
	.Item(cdoSendUserName)          = "donotreply@sportsmgr.us"
	.Item(cdoSendPassword)         = "Shadow@1958"
	.Item(cdoSMTPConnectionTimeout) = 10
	.Update
End With

Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration = objConfig

With objMail
.Subject=arrSubject(RecMail.Fields(2))
.From="SportsManager<donotreply@sportsmanager.us>"
.To=RecMail.Fields(1)
'.BCC = "bhartiya.ravi@gmail.com"
If bln = "T" Then
	objMail.AddAttachment strAttachment
End If
.HTMLBody = strCoachPlayer
.Send
End With
Set objMail=Nothing
ElseIf ((blnNoticeApproved = True And bln="T") Or (blnNoticeDisApproved = True And bln="F")) And .Fields("Type") <> 1 Then '***CHECK APPROVED AND DISAPPROVED FOR COACHES ORG
intCount= intCount + 1

'***SEND EMAIL
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
	.Item(cdoSendUsingMethod)       = cdoSendUsingPort
	.Item(cdoSMTPServer)            = "mail.sportsmgr.us"
	.Item(cdoSMTPServerPort)        = 25
	.Item(cdoSMTPAuthenticate)      = cdoBasic
	.Item(cdoSendUserName)          = "donotreply@sportsmgr.us"
	.Item(cdoSendPassword)         = "Shadow@1958"
	.Item(cdoSMTPConnectionTimeout) = 10
	.Update
End With

Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration = objConfig


With objMail
.Subject=arrSubject(RecMail.Fields(2))
.From="SportsManager<donotreply@sportsmanager.us>"
.To=RecMail.Fields(1)
.BCC = "Copy<copy@sportsmanager.us>"
If bln = "T" Then
	objMail.AddAttachment strAttachment
End If
.HTMLBody = strCoachPlayer
.Send
End With
Set objMail=Nothing
End If 
.MoveNext
Loop
.Close()
End With
Set RecMail = Nothing
If bln = "T" Then
Set fs=CreateObject("Scripting.FileSystemObject")
If fs.FileExists(strAttachment) Then   
  fs.DeleteFile(strAttachment)
End If 
Set fs=Nothing
End If
End Sub

Function PlayerCaoch(ByVal Team)
Dim RecList,SqlQuery,strTable
SqlQuery = "EXECUTE dbo.USP_ROSTER_PLAYER_COACH "&Team
Set RecList = CreateObject("adodb.recordset")
With RecList
.Open SqlQuery,Conn
If .EOF = False Then
strTable = "<table cellpadding=""5"">"
Do While .EOF = False
strTable = strTable &"<tr><td>"&.Fields("Type")&"</td><td>"&.Fields("First")&" "&.Fields("Last")&"</td><td>"&.Fields("Status")&"</td></tr>"
.MoveNext
Loop
strTable = strTable & "</table>"
End If 
.Close()
End With
Set RecList = Nothing
PlayerCaoch = strTable
End Function


Function PdfHtml(ByVal intTeam,ByVal Mode)
Dim RecTeam,strTable,strFileName 
Dim SqlQuery
If Mode="MAYSL" Then
	strHeader="MAYSL SOCCER APPROVED ROSTER"
	strOMORG="MAYSL"
ElseIf Mode="MD" Then
	strOMORG="MYSL"
	strHeader="MIDDLESEX SOCCER APPROVED ROSTER"
ElseIf Mode="NVYSL" Then
	strOMORG="NVYSL"
	strHeader="NVYSL SOCCER APPROVED ROSTER"
ElseIf Mode="PVJSL" Then
	strOMORG="PVJSL"
	strHeader="PVJSL SOCCER APPROVED ROSTER"
End If 
Set RecTeam = CreateObject("adodb.recordset")
SqlQuery = "EXECUTE dbo.USP_ROSTER_TEAM_INFO "&intTeam
With RecTeam
.Open SqlQuery,Conn
If .EOF = False Then
		strHeader = strHeader & "<br/>" & .Fields("Season") & " - " & Year(Date())
		strTeam = .Fields("TeamName")
		strOrg = .Fields("OrgName")
		strLeague =.Fields("League")
		If .Fields("TeamNumber") <> "" Then 
			strTeamID= .Fields("TeamNumber")
		Else
			strTeamID= .Fields("TeamID")
		End If 
		strDiv = .Fields("Div")
		strColor = .Fields("TeamColor")
		If .Fields("LeagueGenders") = 1 Then
			strBoys = "X"
			strGirls = "X"
			strBG = "C"
		ElseIf .Fields("LeagueGenders") = 2 Then
			strBoys = "X"
			strGirls = ""
			strBG = "B"
		Else
			strBoys = ""
			strGirls = "X"
			strBG = "G"
		End If
		strAgeGroup = .Fields("MaxAge") + 1
		If .Fields("TeamNumber") <> "" Then
			strTeamNumber = Replace(.Fields("TeamNumber"),"/","_")
			strTeamNumber = Replace(strTeamNumber,"\","_")
		Else
			strTeamNumber = Replace(.Fields("TeamName"),"/","_")
			strTeamNumber = Replace(strTeamNumber,"\","_")
		End If
		strPosition = .Fields("Pos")
		
End If 
.Close()
End With
Set RecTeam = Nothing
If Month(Date) < 10 Then
strMonth = "0" & Month(Date)
Else
strMonth = Month(Date)
End If
If Day(Date) < 10 Then
strDay = "0" & Day(Date)
Else
strDay = Day(Date)
End If
strFileName = strBG & strAgeGroup & "-" & strDiv & "-" & strTeamNumber & "-" & strMonth & strDay&"-"&intTeam&".pdf"
strFileName = Replace(strFileName,":","")



strTable = "<html><body><table cellpadding=""0"" width=""100%"" ><tr><td align=""center""><b>"&strHeader&"</b></td></tr>"
strTable = strTable & "<tr><td><table cellpadding=""0"" cellspacing=""0"" border=1 width=""100%"" style=""font-size:0.8em;font-weight:bold;""><tbody><tr><td colspan=""2"" width=""50%"">Town/Club: "&strOrg&"</td><td width=""17%"">Date: "& strDate & "</td><td width=""13%"">Original: </td><td width=""20%"">Change: </td></tr><tr><td width=""33%"">Team Name: "&strTeam&"</td><td width=""17%"" nowrap>Age: "&strLeague&"</td><td width=""17%"">Girls: "&strGirls&"</td><td width=""13%"" nowrap>Boys: "&strBoys&"</td><td width=""20%"">Shirt Color: "&strColor&"</td></tr><tr><td colspan=""2"">League:</td><td nowrap>Team ID#: "&strTeamID&"</td><td colspan=""2"">Div/Section: "&strDiv&"</td></tr></tbody></table></td></tr>"
strTable = strTable & "<tr><td align=""center""><table cellpadding=""0"" cellspacing=""0"" width=""100%"" border=1 style=""font-size:0.8em;font-weight:bold;""><thead><tr><td width=""5%"">&nbsp;</td><td width=""35%"" align=""center"">Coach</td><td width=""20%"" align=""center"">Phone</td><td width=""40%"" align=""center"">Email</td></tr></thead><tbody>"
intNum = intNum+1
Set RecCoach = CreateObject("adodb.recordset")
With RecCoach
.Open "EXECUTE dbo.USP_TEAM_COACHES "&intTeam, Conn
Do While .EOF = False 
strTable = strTable & "<tr><td >"&intNum&"</td><td>"&.Fields(0)&"</td><td>"&.Fields(2)&"</td><td>"&.Fields(1)&"</td></tr>"
intNum = intNum+1
.MoveNext
Loop
.Close()
End With
Set RecCoach = Nothing
Do While intNum <=3 
strTable = strTable & "<tr><td>"&intNum&"</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
intNum = intNum+1
Loop

intNum = 0
strTable = strTable & "</tbody></table></td></tr>"
strTable = strTable & "<tr><td align=""center""><table cellpadding=""0"" cellspacing=""0"" width=""100%"" border=1 style=""font-size:0.8em;font-weight:bold;"" ><thead><tr><td width=""5%"">&nbsp;</td><td width=""10%""><b>Shirt#</b></td><td width=""15%"">Last Name</td><td width=""15%"">First Name</td><td width=""10%"">DOB</td><td width=""15%"">Town</td><td width=""15%"">Assigned</td></tr></thead><tbody>"
Set RecPlayer = CreateObject("adodb.recordset")
With RecPlayer
.Open "EXECUTE dbo.USP_TEAM_PLAYERS "&intTeam, Conn
Do While .EOF = False 
intNum = intNum+1
strTable = strTable & "<tr><td width=""30px"">"&intNum&"</td><td width=""80px"">"&.Fields(0)&"&nbsp;</td><td>"&.Fields(1)&"</td><td>"&.Fields(2)&"</td><td>"&.Fields(3)&"</td><td>"&.Fields(4)&"</td><td>"&.Fields(5)&"</td></tr>"
.MoveNext
Loop
.Close()
End With
Set RecPlayer = Nothing
strTable = strTable & "</tbody></table></td></tr>"
strTable = strTable & "<tr><td align=""left""><strong>Transfers:</td></tr><tr><td><table cellpadding=""3"" width=""100%"" cellspacing=""0"" border=1 style=""font-size:12px;font-weight:bold;"">"
For I=1 To 3
strTable = strTable & "<tr><td width=""10%"">"&I&"</td><td width=""10%"">&nbsp;</td><td width=""10%"">&nbsp;</td><td width=""10%"">&nbsp;</td><td width=""10%"">&nbsp;</td><td width=""10%"">&nbsp;</td><td width=""10%"">&nbsp;</td></tr>"
Next
strTable = strTable & "</table></td></tr></table>"
strTable = strTable & "<tr><td><table cellpadding=""3"" width=""100%"" cellspacing=""0"" style=""font-size:12px;font-weight:bold;"" >"
If strOMORG <> "NVYSL" Then 
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Registrar Verification</td><td> ______________________________________________</td><td>Date</td><td> ___________________</td></tr>"
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Boys/Com Verification</td><td> ______________________________________________</td><td>Date</td><td> ___________________</td></tr>"
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Girls/Com Verification</td><td> ______________________________________________</td><td>Date</td><td>___________________</td></tr>"
Else
strTable = strTable & ApproverSignature(intTeam)
End If
strTable = strTable & "</table></td></tr><tr><td><table BORDER=1 CELLPADDING=""1"" width=""100%"" style=""font-size:0.8em;font-weight:bold""><tr><td width=""50%"" align=""center""><b>"&strPosition&"'s Signature</b></td><td align=""center""><b>Club/Town Certification</b></td></tr><tr><td><SPAN style=""font-size:0.8em;font-weight:bold"">I Certify that I will comply with Soccer and bylaws, playing rules, & " & strPosition & "'s Code of Conduct, and know the penalties for non-compliance.<BR><BR>" & strPosition & "'s Signature ______________________</SPAN></td><td><SPAN style='font-size:0.8em;'>All players and all coaches/managers meet all Soccer requirements for affilation and playing age, and the town/club is properly affiliated.<BR><BR>Signature _______________________________</SPAN></td></tr></table></td></tr>"
strTable = strTable & "<tr><td>&nbsp;</td></tr><tr><td><table cellpadding=""1"" width=""100%"" BORDER=1 CELLSPACING=""0"" style=""font-size:0.8em;font-weight:bold""><tr><td>Referee:</td><td>Sched. Date:</td><td>Actual Date:</td></tr><tr><td>Opposing Team:</td><td>Winner:</td><td>Score:</td></tr></table></td></tr>"
strTable = strTable & "</table></body></html>"
strFileName="C:\ScheduleTask\Attachment\"&strFileName
Set Pdf = CreateObject("Persits.Pdf")
Set doc = Pdf.CreateDocument
Set Page = Doc.Pages.Add
Set Image = Doc.OpenImage("C:\ScheduleTask\Approved.jpg")
Set Param = Pdf.CreateParam
Param("x") = 100
Param("y") = 200
Param("ScaleX") =2
Param("ScaleY") =2
Page.Background.DrawImage Image, Param
Doc.ImportFromUrl strTable
Doc.Save strFileName,True
Set Pdf = Nothing
PdfHtml = strFileName
End Function



Function ApproverSignature(ByVal TeamID)
Dim strSignature,strSQL
Set ObjFS=CreateObject("Scripting.FileSystemObject")
strSQL ="EXECUTE dbo.USP_ROSTER_FORM_APPROVER_SIGNATURE " & TeamID & ",1"

Set RecSignature = CreateObject("adodb.recordset")
With RecSignature
.Open strSQL,Conn
If .EOF = False Then
strSignature  = "<tr><td colspan=""4"">"
Do While .EOF = False
strLogo = "C:\HostingSpaces\cloudspo\sportsmgr.us\wwwroot\"&Replace(.Fields(0),"/","\")
If ObjFS.FileExists(strLogo) then
	strSignature =  strSignature & "<img src="""&strLogo&""" border=""0""/>&nbsp;&nbsp;&nbsp;&nbsp;"
End If
.MoveNext
Loop
strSignature = strSignature & "</td></tr>"
End If 
End With 
Set RecSignature = Nothing : Set ObjFS = Nothing
ApproverSignature = strSignature
End Function

Function PdfHtmlWithPicture(ByVal TeamID,ByVal Mode,ByVal OrgID)
Dim RecTeam,strTable,strFileName 
Dim SqlQuery
If Mode="MAYSL" Then
	strHeader="MIDLAND AREA YOUTH SOCCER APPROVED ROSTER"
	strOMORG="MAYSL"
ElseIf Mode="MD" Then
	strOMORG="MYSL"
	strHeader="MIDDLESEX YOUTH SOCCER LEAGUE APPROVED ROSTER"
ElseIf Mode="NVYSL" Then
	strOMORG="NVYSL"
	strHeader="NASHOBA VALLEY YOUTH SOCCER LEAGUE APPROVED ROSTER"
ElseIf Mode="PVJSL" Then
	strOMORG="PVJSL"
	strHeader="PIONEER VALLEY JUNIOR SOCCER LEAGUE APPROVED ROSTER"
End If 

Set RecTeam = CreateObject("adodb.recordset")
SqlQuery = "EXECUTE dbo.USP_ROSTER_TEAM_INFO "&TeamID
With RecTeam
.Open SqlQuery,Conn
If .EOF = False Then
	    strHeader = strHeader & "<br/>" & .Fields("Season") & " - " & Year(Date())
		strTeam = .Fields("TeamName")
		strOrg = .Fields("OrgName")
		strLeague =.Fields("League")
		If .Fields("TeamNumber") <> "" Then 
			strTeamID= .Fields("TeamNumber")
		Else
			strTeamID= .Fields("TeamID")
		End If 
		strDiv = .Fields("Div")
		strColor = .Fields("TeamColor")
		If .Fields("LeagueGenders") = 1 Then
			strBoys = "X"
			strGirls = "X"
			strBG = "C"
		ElseIf .Fields("LeagueGenders") = 2 Then
			strBoys = "X"
			strGirls = ""
			strBG = "B"
		Else
			strBoys = ""
			strGirls = "X"
			strBG = "G"
		End If
		strAgeGroup = .Fields("MaxAge") + 1
		If .Fields("TeamNumber") <> "" Then
			strTeamNumber = Replace(.Fields("TeamNumber"),"/","_")
			strTeamNumber = Replace(strTeamNumber,"\","_")
		Else
			strTeamNumber = Replace(.Fields("TeamName"),"/","_")
			strTeamNumber = Replace(strTeamNumber,"\","_")
		End If
		strPosition = .Fields("Pos")
		
End If 
.Close()
End With
Set RecTeam = Nothing
If Month(Date) < 10 Then
strMonth = "0" & Month(Date)
Else
strMonth = Month(Date)
End If
If Day(Date) < 10 Then
strDay = "0" & Day(Date)
Else
strDay = Day(Date)
End If
strFileName = strBG & strAgeGroup & "-" & strDiv & "-" & strTeamNumber & "-" & strMonth & strDay&"-"&TeamID&".pdf"
strFileName = Replace(strFileName,":","")



If blnApproved = "T" Then '***ROSTER IS Approved
strSQL = "SELECT CONVERT(VARCHAR(10),MAX(AppUpdate),101) AS ApprovedDate  FROM RosterApp WHERE (TeamID = " & TeamID & ")"
Set RecObj = CreateObject("adodb.recordset")	



With RecObj
.Open strSQL,Conn
If .EOF = False Then
strDate = "Apprvd: " & .Fields(0)
Else
strDate = "Date: " & Date
End If 
.Close()
End With
Set RecObj = Nothing
Else
strDate = "Date: " & Date
End If 


strTable = "<html><body><table cellpadding=""0"" width=""100%"" ><tr><td align=""center""><b>"&strHeader&"</b></td></tr>"
strTable = strTable & "<tr><td><table cellpadding=""0"" cellspacing=""0"" border=1 width=""100%"" "
strTable = strTable & "style=""font-size:0.8em;font-weight:bold;""><tbody><tr>"
strTable = strTable & "<td colspan=""2"" width=""50%"">Town/Club: "&strOrg&"</td>"
strTable = strTable & "<td width=""17%"">"& strDate & "</td><td width=""13%"">Original: </td>"
strTable = strTable & "<td width=""20%"">Change: </td></tr><tr><td width=""33%"">Team Name: "&strTeam&"</td>"
strTable = strTable & "<td width=""17%"" nowrap>Age: "&strLeague&"</td><td width=""17%"">Girls: "&strGirls&"</td>"
strTable = strTable & "<td width=""13%"" nowrap>Boys: "&strBoys&"</td><td width=""20%"">Shirt Color: "&strColor&"</td></tr>"
strTable = strTable & "<tr><td colspan=""2"">League:</td><td nowrap>Team ID#: "&strTeamID&"</td>"
strTable = strTable & "<td colspan=""2"">Div/Section: "&strDiv&"</td></tr></tbody></table></td></tr>"

strTable = strTable & "<tr><td>"

jaja = 0

strSQL = "EXECUTE dbo.USP_TEAM_INFO_TASK_PROGRAM " & TeamID & "," & OrgID
jaja = 0
Set RecJA = CreateObject("adodb.recordset")
With RecJA
.Open strSQL,Conn
Do While .EOF= False 
arrCoachName(jaja) = RecJA("Name") 


If RecJA("phcell") = "" Then
	strPhone = RecJA("phhome")
Else 
	strPhone = RecJA("phcell")
End If 

If strPhone = "" Then
strPhone = "&nbsp;"
End If 

arrCoachPhone(jaja) = strPhone
arrCoachEmail(jaja) = RecJA("email")
arrCoachPics(jaja) = ShowCoachImage(.Fields("Photo"))
jaja = jaja + 1
.MoveNext
Loop
End With
Set RecJA = Nothing
intNum = 0

strTable = strTable & "<table width=""100%"" border=""1"" style=""font-weight:bold;font-size:0.8em;""><tbody><tr><td width=""1%"">&nbsp;</td><td width=""25%"">Coah</td><td width=""8%"">Phone</td><td width=""34%"">Email</td><td width=""7%"" align=""center"">1</td><td width=""7%"" align=""center"">2</td><td width=""7%"" align=""center"">3</td><td width=""11%"" align=""center"">4</td></tr><tr><td>1</td><td>"&arrCoachName(0)&"</td><td>"&arrCoachPhone(0)&"</td><td>"&arrCoachEmail(0)&"</td><td rowspan=""4"" style=""vertical-align:top"">"&arrCoachPics(0)&"</td><td rowspan=""4""  style=""vertical-align:top"">"&arrCoachPics(1)&"</td><td rowspan=""4""  style=""vertical-align:top"">"&arrCoachPics(2)&"</td><td rowspan=""4""  style=""vertical-align:top"">"&arrCoachPics(3)&"</td></tr><tr><td align=""center"">2</td><td>"&arrCoachName(1)&"</td><td>"&arrCoachPhone(1)&"</td><td>"&arrCoachEmail(1)&"</td></tr><tr><td>3</td><td>"&arrCoachName(2)&"</td><td>"&arrCoachPhone(2)&"</td><td>"&arrCoachEmail(2)&"</td></tr><tr><td>4</td><td>"&arrCoachName(3)&"</td><td>"&arrCoachPhone(3)&"</td><td>"&arrCoachEmail(3)&"</td></tr></tbody></table>"
strTable = strTable & "</td></tr>"

Set dicPlayers=CreateObject("Scripting.Dictionary")
Set RecPlayers = CreateObject("ADODB.Recordset")
strSQL = "EXECUTE dbo.USP_ROSTER_FORM_DISPLAY_PLAYERS_TASK_PROGRAM "&TeamID


With RecPlayers
.Open strSQL,Conn
If .EOF = False Then
Do While .EOF = False
arrImg = ShowPlayerImagePlayer(RecPlayers.Fields("ThumbPhoto"))
dicPlayers.Add CStr(.Fields("PlayerID")),arrImg 
.MoveNext
Loop
End If
.Close()
End With
Set RecPlayers = Nothing


arrPlayerKeys = dicPlayers.Keys
arrPlayerImages = dicPlayers.Items

strTable = strTable & "<tr><td align=""center"">"
strTable = strTable & "<table border=""1"" style=""font-size:0.8em;width:670px;font-weight:bold""><thead><tr><th>&nbsp;</th><th>Shirt#</th><th>LastName</th><th>FirstName</th><th>DOB</th>"
If blnForceGrade = "T" Then 
	strTable = strTable & "<th>Grade</th>"
End If 
strTable = strTable & "<th>1</th><th>2</th><th>3</th><th>Town</th>"
				
 

strTable = strTable & "</tr></thead><tbody>"

Set RecPlayer = CreateObject("adodb.recordset")
With RecPlayer
.Open "EXECUTE dbo.USP_TEAM_PLAYERS "&TeamID, Conn
Do While .EOF = False
pc = pc + 1


If pc = 1 Or pc = 4 Or pc = 7 Or pc = 10 Or pc = 13 Or pc = 16 Or pc = 19 Or pc = 22 Or pc =25 Or pc = 28 Or pc = 31 Or pc = 34 Then 
intPicNum = 1
strTable = strTable & "<tr><td align=""center"">"&pc&"-"&intPicNum&"</td><td align=""center"">"&.Fields("UniformNumber")&"</td><td>"&.Fields("Last")&"</td><td>"&.Fields("First")&"</td><td>"&.Fields("birthday")&"</td>"

If blnForceGrade = "T" Then 
	strTable = strTable &  "<td align=""center"">"&.Fields("Grade") & "</td>"
End If 


strTable = strTable &  "<td rowspan=""3"" align=""center"">"&arrPlayerImages(pcImgNum)&"</td>"


If pcImgNum+1 <= UBound(arrPlayerImages) Then
strTable = strTable &  "<td rowspan=""3"" align=""center"">"&arrPlayerImages(pcImgNum+1)&"</td>"
Else
strTable = strTable & "<td rowspan=""3"" align=""center"">&nbsp;</td>"
End If 

If pcImgNum+2 <= UBound(arrPlayerImages) Then
strTable = strTable & "<td rowspan=""3"" align=""center"">"&arrPlayerImages(pcImgNum+2)&"</td>"
Else
strTable = strTable & "<td rowspan=""3"" align=""center"">&nbsp;</td>"
End If

strTable = strTable & "<td>"&.Fields("City")&"</td></tr>"
Else
strTable = strTable &  "<tr><td align=""center"">"&pc&"-"&intPicNum&"</td><td align=""center"">"&.Fields("UniformNumber")&"</td><td>"&.Fields("Last")&"</td><td>"&.Fields("First")&"</td><td>"&.Fields("birthday")&"</td>"

If blnForceGrade = "T" Then 
	strTable = strTable &  "<td align=""center"">"&.Fields("Grade") & "</td>"
End If 
strTable = strTable & "<td>"&.Fields("City")&"</td></tr>"
End If
pcImgNum = pcImgNum + 1 : intPicNum = intPicNum + 1
.MoveNext
Loop
End With




strTable = strTable & "</tbody></table>"



strTable = strTable & "<table cellpadding=""3"" width=""100%"" cellspacing=""0"" style=""font-size:12px;font-weight:bold;"" >"
If strOMORG <> "NVYSL" Then 
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Registrar Verification</td><td> ______________________________________________</td><td>Date</td><td> ___________________</td></tr>"
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Boys/Com Verification</td><td> ______________________________________________</td><td>Date</td><td> ___________________</td></tr>"
strTable = strTable & "<tr><td nowrap width=""40%"">"&strOMOrg&" Girls/Com Verification</td><td> ______________________________________________</td><td>Date</td><td>___________________</td></tr>"
Else
strTable = strTable & ApproverSignature(TeamID)
End If
strTable = strTable & "</table></td></tr><tr><td><table BORDER=1 CELLPADDING=""1"" width=""100%"" style=""font-size:0.8em;font-weight:bold""><tr><td width=""50%"" align=""center""><b>"&strPosition&"'s Signature</b></td><td align=""center""><b>Club/Town Certification</b></td></tr><tr><td><SPAN style=""font-size:0.8em;font-weight:bold"">I Certify that I will comply with Soccer and bylaws, playing rules, & " & strPosition & "'s Code of Conduct, and know the penalties for non-compliance.<BR><BR>" & strPosition & "'s Signature ______________________</SPAN></td><td><SPAN style='font-size:0.8em;'>All players and all coaches/managers meet all Soccer requirements for affilation and playing age, and the town/club is properly affiliated.<BR><BR>Signature _______________________________</SPAN></td></tr></table></td></tr>"
strTable = strTable & "<tr><td>&nbsp;</td></tr><tr><td><table cellpadding=""1"" width=""100%"" BORDER=1 CELLSPACING=""0"" style=""font-size:0.8em;font-weight:bold""><tr><td>Referee:</td><td>Sched. Date:</td><td>Actual Date:</td></tr><tr><td>Opposing Team:</td><td>Winner:</td><td>Score:</td></tr></table></td></tr>"
strTable = strTable & "</table></body></html>"
strFileName="C:\ScheduleTask\Attachment\"&strFileName
Set Pdf = CreateObject("Persits.Pdf")
Set doc = Pdf.CreateDocument
Set Page = Doc.Pages.Add
Set Image = Doc.OpenImage("C:\ScheduleTask\Approved.jpg")
Set Param = Pdf.CreateParam
Param("x") = 100
Param("y") = 200
Param("ScaleX") =2
Param("ScaleY") =2
Page.Background.DrawImage Image, Param
Doc.ImportFromUrl strTable
Doc.Save strFileName,True
Set Pdf = Nothing
PdfHtmlWithPicture = strFileName
End Function





Function ShowCoachImage(strImage)

If IsNull(strImage) = True Or strImage = "" Then
	ShowCoachImage = "Missing Photo"
	Exit Function
End If


If IsPhotoExists(strImage) = True Then
	ShowCoachImage = "<img src="""& strImage & """ style=""width:40px;height:40px""/>"
Else
	ShowCoachImage = "Missing Photo"
End If 
End Function

Function ShowPlayerImagePlayer(strImage)

If IsNull(strImage) = True Or strImage = "" Then
	ShowPlayerImagePlayer = "Missing Photo"
	Exit Function
End If


If IsPhotoExists(strImage) = True Then
	ShowPlayerImagePlayer = "<img src="""& strImage & """ style=""width:50px;height:50px""/>"
Else
	ShowPlayerImagePlayer = "Missing Photo"
End If 
End Function

Function IsPhotoExists(strPhoto)
Set ObjFS=CreateObject("Scripting.FileSystemObject")
IsPhotoExists =  ObjFS.FileExists(strPhoto) 
End Function
