<%@ Language=VBScript %>
<!--#INCLUDE file="ADOVBS.inc"-->
<%
	Response.Buffer=true
	DIM str_empresa, str_nombre_empresa, lon_folio
	dim candidateName, candidatePuesto, candidateCompany	
	DIM int_w, int_h
	candidateName = ""
	candidatePuesto = ""
	candidateCompany = ""
	int_w="100%"
	int_h="100%"

	str_empresa= Request.Cookies("sieps")("empresa")
	str_nombre_empresa=Request.Cookies("sieps")("nombre_empresa")


	str_bd= application("bd_sieps")

	set conn = server.CreateObject ("ADODB.Connection")
	set rs = server.CreateObject ("ADODB.Recordset")

	conn.Open str_bd

	lon_folio = Request.Cookies("sieps")("folio")

	conn.BeginTrans
	'sqlQuery = "UPDATE solicitud SET soli_estatus ='Aplicado'  WHERE soli_folio =" & lon_folio
	' Cambia el passwd para que el usuario ya no pueda entrar al sistema 
	sqlQuery = "UPDATE solicitud SET soli_estatus ='Aplicado', soli_password='Aplicado!'  WHERE soli_folio =" & lon_folio 
	On Error Resume Next
	conn.Execute sqlQuery,,1
	handleError(conn)
	conn.CommitTrans
	
	'obtengo la info del candidato
	getCandidateInfo(lon_folio) 
	
	' Mando el correo de notificacion de finalizacion
	sendEmail("jonathan-delgado@manemployee.com")
	
	'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
	
sub getCandidateInfo(lon_folio) 
	
	sqlQuery = "SELECT soli_nombre, empr_clave, pues_clave FROM solicitud WHERE soli_folio= " & lon_folio
	rs.Open sqlQuery, conn, adOpenStatic,adLockReadOnly,1
	if rs.EOF= FALSE THEN
		candidateName = rs.Fields("soli_nombre")
		candidatePuesto = rs.Fields("pues_clave")
		candidateCompany = rs.Fields("empr_clave")
	end if	
	rs.close
end sub
	
Function sendEmail(toMail)
	dim ret
	dim msg
	msg = ""
	ret = 1
	
	'IMPORTANTE. Estos parametros se configuran cuando es un servidor de correo remoto. 
	' Esto es fuera del servidor web. Si el servicio de mail recide en el mismo servidor, no se configuran
	
	set cdoConfig = CreateObject("CDO.Configuration")
	With cdoConfig.Fields 
		.Item(application("itemSendUsing")) = application("sendUsing")
		'Name or IP of Remote SMTP Server
        .Item(application("itemNameServer")) = application("smtpServer")
		'Server port (typically 25)
        .Item(application("itemNamePort")) = application("smtpPort")
		.Item(application("itemAuthenticate")) = application("authenticate")
		.Item(application("itemSendUserName")) = application("sendUserName")
		.Item(application("itemSendPassword")) = application("sendPassword")
        .Update 
    End With 
	
	' el texto del mensaje es una constante de application scope
	msg = application("msgTerminacion")
	msg = Replace(msg,"%candidateName%",candidateName)
	msg = Replace(msg,"%candidatePuesto%",candidatePuesto)
	msg = Replace(msg,"%candidateCompany%",candidateCompany)
	
	'set objMessage = server.CreateObject("CDONTS.NewMail")
	set objMessage = CreateObject("CDO.Message")
	
	With objMessage
        Set .Configuration = cdoConfig
        .From = "evaluacion@sieps.com.mx"
		.Cc = "nelly-jimenez@manemployee.com"
        .To = toMail
        .Subject = "Termino de evaluación en SiEPs"
        .HTMLBody = msg
    End With 
	
	on error Resume Next
	objMessage.Send	
	if Err<>0 then
		ret = 0 'Hay error
	end if	
		
	set objMessage = nothing
	set cdoMessage = Nothing  
	sendEmail = ret
end Function	

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	
%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<link REL="stylesheet" TYPE="text/css" HREF="stylesheet.css">
</head>
<!--#INCLUDE FILE="uti_utilerias_aplicacion.asp"-->

<script LANGUAGE="javascript">
<!--

function abortar()
{
	self.close();
}



//-->
</script>
<body class="body" topmargin="6" bottommargin="6" leftmargin="6" rightmargin="6" bgColor="slategray" onkeydown="evento()">
<!--#INCLUDE FILE="uti_fondo.asp"-->

<table width="100%" height="100%" valign="middle" border="0" bgcolor="white" cellspacing="0" cellpadding="0">
	<tr>
		<td height="100%" width="100%" align="center" valign="middle">
			<table width="100%" valign="middle" border="0" bgcolor="white" cellspacing="0" cellpadding="0">
				<tr>		
					<td height="80" width="100%" align="center" valign="middle">
						<font class="titulo_instrucciones">Fin de la Evaluación...</font>					</td>
				</tr>
				<tr>		
					<td width="100%" align="center" valign="middle">
						<br>					</td>
				</tr>
				<tr>		
					<td height="80" width="100%" align="center" valign="middle">
						<p><font class="titulo_instrucciones">¡Gracias por su colaboración en la</font></p>
						<p><font class="titulo_instrucciones">realizaci&oacute;n de la presente evaluaci&oacute;n!</font></p>
						<p>					    
						  <input type="hidden" name="SALIR">
						  <img src="images/logo_empresa.jpg" alt="logo" width="220" height="250" align="absbottom" longdesc="logo_fin"></p></td>
				</tr>
			</table>		</td>
	</tr>
</table>

<!--#INCLUDE FILE="uti_calce.asp"-->
</body>
</html>
