<%@ Language=VBScript %>
<!--#INCLUDE file="ADOVBS.inc"-->
<%
	dim lon_folio, tmpVal, auxVal
	dim sqlQuery, rs, conn
	dim str_clave_prueba(30), str_prueba(30)

	for i=1 to 30
		str_prueba(i)=""
	next

	dsn= application("bd_sieps")

	set conn = server.CreateObject ("ADODB.Connection")
	set rs = server.CreateObject ("ADODB.Recordset")
	On Error Resume Next
	conn.Open dsn	
	handleError(conn)

	' Las pruebas seleccionadas
'	selectedTests = Request.Form("selectedTests")
	lon_folio= Request.Cookies("sieps")("folio")
	Response.Cookies("sieps")("clave_prueba")=""

	conn.BeginTrans
	' Se elimina el registro del folio
	sqlQuery = "DELETE FROM pruebas_seleccionadas WHERE soli_folio =" & lon_folio
	conn.Execute sqlQuery,,1
	
	sqlQuery = "INSERT INTO pruebas_seleccionadas (soli_folio, "
'	dim lenParameters
'	lenParameters = Request.Form("selectedForm").Count
'sendMensajeToConsole("Cuantas: "&lenParameters) Request.Form("selectedForm").Count
	for x=1 to Request.Form("selectedTests").Count 'lenParameters
		tmpVal = tmpVal & "prue_clave_" & x
		tmpVal = tmpVal & ","
		auxVal = auxVal & "'" & Request.Form("selectedTests")(x)
		auxVal = auxVal	& "',"
	next
	
	tmpVal = Left(tmpVal,Len(tmpVal)-1)
	auxVal = Left(auxVal,Len(auxVal)-1)
	
	sqlQuery = sqlQuery & tmpVal & " )"
	sqlQuery = sqlQuery & " VALUES ("&lon_folio&", "
	sqlQuery = sqlQuery & auxVal & " )"
'sendMensajeToConsole("El query: "&sqlQuery)

	On Error Resume Next
	conn.Execute sqlQuery,,1
	handleError(conn)
	conn.CommitTrans
	
	'clean up
	If rs.State = adStateOpen then
		rs.Close
	End If
	If conn.State = adStateOpen then
		conn.Close
	End If
	Set rs = Nothing
	Set conn = Nothing
		
	Response.Redirect("aplicacion_inicio.asp?accion=iniciar")
	
sub handleError(connectionRef)
	dim objErr
	dim str_c
	dim strrr, flag
	flag = 0

	if connectionRef.Errors.Count <> 0 Then
		str_c = str_c & "Count: " 
		str_c = str_c & connectionRef.Errors.Count
		for each objErr in connectionRef.Errors
			if objErr.Number <> 0 then ' Number = 0 el error es meramente informativo
				str_c = str_c & " Number: "
				str_c = str_c & objErr.Number			
				
				str_c = str_c & " Description: "
				str_c = str_c & objErr.Description  
			  
				str_c=str_c&" Native error: "
				str_c=str_c&objErr.NativeError 
				  
				str_c=str_c&" SQL state: "
				str_c=str_c&objErr.SQLState
				flag = 1
			end if
		next		
		if flag <> 0 then
			' clean up		
			if conn.State = adStateOpen then
				conn.Close
			end if
			
			set rs = Nothing
			set conn = Nothing
			set connectionRef = nothing
			
			strrr = "uti_console.asp?mensaje=" & "Error: " & str_c 
			Response.Redirect(strrr)
		end if		
	end if	
end sub

sub sendMensajeToConsole(mensaje)
	dim strrr
	strrr="uti_console.asp?mensaje=" & mensaje
	Response.Redirect(strrr)
end sub
%>