<?php
include('init.php');
include('libs/functions.php');


if (checklogin($userID, "menu.php")) {
        if (isset($_REQUEST['id'])) { 
    	if (($userID) <> ($_REQUEST['id'])){
                   echo "Failed";
            } else {
	            $user_id = scrub_sql(scrub_white_list($_REQUEST['id'], 'NUMBERONLY'), 5);


	            $sql = "SELECT fname, lname, email, username, account_type FROM tb_user WHERE user_id=$user_id";
	            $rs = $db->Execute($sql);

	            $fname = $rs->fields('fname');
	            $lname = $rs->fields('lname');
	            $email = $rs->fields('email');
	            $username = $rs->fields('username');
	            $account_type = $rs->fields('account_type');


	            if ("CF" == $account_type){
	                    $message = ("

	                    <HTML>
	                    <BODY>


	                    Dear VRSS Automated Uploads Administrator,
	                    <BR><BR>

	                    The user '<b>$username</b>' is requesting access to the VRSS Automated Upload section of the VRSS application.<br>
	                    <br>Please review this request by clicking the following link and taking appropriate action on this user's account page:<br><center>
	                    <A HREF=https://admintest.vrss.domain/VRSS/edit_CF_users.asp?u=$user_id>https://admintest.vrss.domain/VRSS/edit_CF_users.asp?u=$user_id</A></center>
	                    <BR><BR>


	                    Thank you.
	                    <BR>
	                    <HR>
	                    </BODY></HTML>
	                ");
	            }
	            elseif ("CS" == $account_type){
	                    $message = ("

	                    <HTML>
	                    <BODY>


	                    Dear VRSS Automated Uploads Administrator,
	                    <BR><BR>

	                    The user '<b>$username</b>' is requesting access to the VRSS Automated Upload section of the VRSS application.<br>
	                    <br>Please review this request by clicking the following link and taking appropriate action on this user's account page:<br><center>
	                    <A HREF=https://admintest.vrss.domain/VRSS/edit_CS_users.asp?u=$user_id>https://admintest.vrss.domain/VRSS/edit_CS_users.asp?u=$user_id</A></center>
	                    <BR><BR>


	                    Thank you.
	                    <BR>
	                    <HR>
	                    </BODY></HTML>
	                ");




	            }

	        	$headers = "From: $email\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";
		
	                //DEV & PreProd
	                mail( "            @domain;         @domain;$email", "VRSS - Activate Automated File Transfer: $username (UID $userID)", $message, $headers );


	                //Prod
	                //mail( "VRSS_AutomatedUploads@domain;$email", "VRSS - Activate Automated File Transfer: $username (UID $userID)", $message, $headers );
	        $sql = "UPDATE tb_user set vrss_automated=9  WHERE user_id=$user_id";
	        $rs = $db->Execute($sql);
	        
	        echo "Success for $username!";
	    }
    }
    else{
        echo "Failed";
    }


} // end check login

?>
