<?php
require_once('../../config.php');
global $USER, $CFG, $DB;

$logouturl = new moodle_url('/login/logout.php', array('sesskey' => sesskey()));
                    $userobj = new stdClass();
                    $userobj->id = $USER->id;
                    $userobj->suspended = 1;
                    $return = $DB->update_record('user', $userobj);
                if ($return) {
                        //send_account_suspend_email_to_user();
                        $to = $USER->email;
                        $fname = $USER->firstname;
                        $lname = $USER->lastname;
                        $sitename = $DB->get_field('course', 'fullname', array('id' => 1));
			$subject = "Academy of Young Ohio Drivers: Your account has been blocked.";
			$txt = "Oh dear...your account was blocked because you did not answer your security questions correctly within the timeframe. Please confirm the following information, and we will get you back on track!";
			$txt .= "\n\n";
		    $txt .= " - Your name\n";
		    $txt .= " - Your date of birth\n";
		    $txt .= " - Your favorite color\n";
		    $txt .= " - Your middle initial\n";	
		    $txt .= " - Your NATURAL hair color\n";
		    $txt .= " - Your eye color\n";
		    
		    $txt .= "";
		    $txt .= "We will respond to your email to let you know your account is reopened.";
			$headers = "From: CustomerCare@OhioACA.com";
			mail($to,$subject,$txt,$headers);
                    }
                    echo "<script type='text/javascript'>alert('Oh dear...your account has been blocked because you did not answer your security questions correctly within the time frame. You will be logged out of the site after clicking the OK button below. Please go to your email account and respond to the email we just sent you, and get you back on track!')</script>";
                    echo "<script>top.window.location.href='$logouturl'; </script>";
                    
?>