<?php 
class eventclass_senuc_descomplica  extends eventsBase
{ 
	function eventclass_senuc_descomplica()
	{
	// fill list of events
		$this->events["BeforeAdd"]=true;

		$this->events["BeforeEdit"]=true;

		$this->events["AfterAdd"]=true;

		$this->events["AfterEdit"]=true;

		$this->events["AfterDelete"]=true;


//	onscreen events


	}
// Captchas functions	

//	handlers

		
		
		
		
		
		
		
		
		
		
				// Before record added
function BeforeAdd(&$values,&$message,$inline,&$pageObject)
{

		
$values["operador"]= $_SESSION["id_operador"];
//**********  Check if specific record exists  ************
global $conn;
$strSQLExists2 = "select * from senuc_descomplica where login='".$values["login"]."'";
$rsExists2 = db_query($strSQLExists2,$conn);
$data2=db_fetch_array($rsExists2);
if($data2)
{
	
echo"<script type='text/javascript'>";

        echo "alert('LOGIN DE ACESSO JÁ ESTÁ VINCULADO A OUTRO ALUNO!');";

echo "</script>";
return false;


}

$strSQLExists3 = "select * from senuc_descomplica_logins where id_aluno='".$values["id_aluno"]."'";
$rsExists3 = db_query($strSQLExists3,$conn);
$data3=db_fetch_array($rsExists3);
if($data3)
{
	
echo"<script type='text/javascript'>";

        echo "alert('ALUNO JÁ ESTÀ VINCULADO A OUTRO LOGIN!');";

echo "</script>";
return false;


}

//**********  Check if specific record exists  ************

$strSQLExists = "select * from senuc_aluno where id=".$values["id_aluno"];
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
$values["id_nucleo"] = $data["idnucleo"];
$values["id_regional"] = $data["idregional"];

// Place event code here.
// Use "Add Action" button to add code snippets.

return true;
;		
} // function BeforeAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Before record updated
function BeforeEdit(&$values,$where,&$oldvalues,&$keys,&$message,$inline,&$pageObject)
{

		$values["operador"]= $_SESSION["id_operador"];


//**********  Check if specific record exists  ************
global $conn;
$strSQLExists2 = "select * from senuc_descomplica where login='".$values['login']."'";
$rsExists2 = db_query($strSQLExists2,$conn);
$data2=db_fetch_array($rsExists2);
if($data2)
{
	
echo"<script type='text/javascript'>";

        echo "alert('LOGIN DE ACESSO JÁ ESTÁ VINCULADO A OUTRO ALUNO!');";

echo "</script>";
return false;


}

//**********  Check if specific record exists  ************

$strSQLExists = "select * from senuc_aluno where id=".$values['id_aluno'];
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
$values['id_nucleo'] = $data["idnucleo"];
$values['id_regional'] = $data["idregional"];


// Place event code here.
// Use "Add Action" button to add code snippets.

return true;
;		
} // function BeforeEdit

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
				// After record added
function AfterAdd(&$values,&$keys,$inline,&$pageObject)
{

		global $conn;
$strSQLExists = "select * from senuc_aluno where id=".$values["id_aluno"];
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
 
 
 
$email=$data["email"];
$from="site@educafro.org.br";
$msg="Prezado usuário, seu acesso ao site DESCOMPLICA doi liberado com sucesso!<br><br>
Através do site DESCOMPLICA você passa a ter acesso a mais de 15.000 aulas gravadas e a aulas ao vivo todos os dias pelo Portal<br><br>
O Acesso pelo site DESCOMPLICA só pode ser feito através do PORTAL DE ALUNOS EDUCAFRO em local específico dentro do referido sistema<br><br>
Para ter acesso ao Portal de Alunos Educafro basta clicar aqui <a href=\"https://www.educafro.org.br/alunos/senuc_descomplica_avaliacao_list.php\" target=\"_new\">aqui</a><br><br>
O login é o seu CPF e a senha incial de acesso é 12345.<br><br>
Os dados para acessar o DESCOMPLICA estarão na tela, dentro do Portal de Alunos Educafro<br><br>

=====================<br><br>";
$subject="Educafro - Acesso liberado ao DESCOMPLICA";
$attachments = array();
$ret=runner_mail(array('to' => $email, 'subject' => utf8_encode($subject),  'htmlbody' => $msg, 'charset' => 'UTF-8', 'from'=>$from, 'attachments' => $attachments));
if(!$ret["mailed"])
	echo $ret["message"];
//**********  Insert a record into another table  ************
global $conn;
$strSQLInsert = "update senuc_descomplica_logins set id_nucleo =".$values['id_nucleo'].",id_aluno=".$values['id_aluno'].",id_regional=".$values['id_regional']." , situacao=0 where login='".$values['login']."'";
db_exec($strSQLInsert,$conn);

// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function AfterAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// After record updated
function AfterEdit(&$values,$where,&$oldvalues,&$keys,$inline,&$pageObject)
{

		global $conn;
$strSQLInsert = "update senuc_descomplica_logins set id_nucleo =".$values['id_nucleo'].",id_aluno=".$values['id_aluno'].",id_regional=".$values['id_regional']." , situacao=0 where login='".$values['login']."'";
db_exec($strSQLInsert,$conn);

// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function AfterEdit

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
				// After record deleted
function AfterDelete($where,&$deleted_values,&$message,&$pageObject)
{

		global $conn;
$strSQLInsert = "update senuc_descomplica_logins set id_nucleo =NULL ,id_aluno=NULL,id_regional=NULL , situacao=1 where login='".$deleted_values['login']."'";
db_exec($strSQLInsert,$conn);


// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function AfterDelete

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//	onscreen events

} 
?>
