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


if (checklogin($userID, "menu.php")) {

    print_header();
    $terms = "Placeholder";

    if (isset($_REQUEST['id'])) { 
            if (($userID) <> ($_REQUEST['id'])){?>
                <center><h1>Error: Incorrect User ID.</h1><br><button type='button' onclick='window.close()'>Close Window</button></center>
           <? } else {
                $user_id = scrub_sql(scrub_white_list($_REQUEST['id'], 'NUMBERONLY'), 5);

                $sql = "SELECT fname, lname, email, username, vrss_automated 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');
                $vrss_automated = $rs->fields('vrss_automated');

                ?>

                <script>
                function submit_auto_request(id) {

                var userID = document.getElementById("hid_id").value;
                div = document.getElementById("request_response");

                //Set up the XMLHttpRequest object, here it is named ‘xmlhttp’

                    if (window.XMLHttpRequest)
                    {  // code for IE7+, Firefox, Chrome, Opera, Safari
                      xmlhttp=new XMLHttpRequest();
                    }
                    else
                    {  // code for IE6, IE5
                                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

                    }
                                // The function that gets called everytime the state changes
                    xmlhttp.onreadystatechange=function()
                    {
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                      {
                           
                            var response;
                            response = xmlhttp.responseText;

                            document.getElementById("request_response").innerHTML = "<center>Your VRSS Automated Uploads request has been submitted. You will receive a confirmation of this request shortly. Thank you.<br></center>";

                            document.getElementById("submit_request").disabled=true;
                      }
                      else
                      {
                        document.getElementById("request_response").innerHTML = "<center>Sending request...</center>";
                        document.getElementById("submit_request").disabled=true;
                      }

                    }
                            var r=confirm("Are you sure you want to submit this request? \n\nIf not, please click Cancel to return to the Terms & Conditions.");
                                if (r == true)
                                {
                                    //var Url = "save_co_nums.asp?r=" + hid_r + "&co=" + new_cos + "&nocache=" + new Date().getTime();
                                    var Url = "send_automated_request.php?id=" + userID + "&nocache=" + new Date().getTime();
                                    xmlhttp.open("GET",Url,true);
                                    xmlhttp.send();
                                }   
                                else
                                {
                                }
                        }

            </script>
            <h1 align="center">VRSS Automated Uploads<!-- END: PAGE TITLE --></h1>
            <h2 align="center">Terms and Conditions</h2>
                <table border=1 align=center>
                    <tr align=center><td><?=$terms?></td></tr>
                    <tr align=center>
                        <? if (9 == $vrss_automated) {?>
                            <td>
                                <i>You have previously submitted your VRSS Automated Upload access request, and it is still under review. <br>If you would like a status update, please contact the VRSS Support group through the <a href='/support.php'>Support</a> page.</i>
                            <br><br>
                                <input type='button' id='submit_request' name='submit_request' value='Send Automated Access Request' onclick='submit_auto_request(<?=$user_id?>);' DISABLED><br><br>
                            </td>

                        <? } else if (0 == $vrss_automated) { ?>
                         
                            <td>
                                <b>Please click the below button only if you agree to the Terms and Conditions presented above:</b>
                            <br><br>
                                <input type='button' id='submit_request' name='submit_request' value='Send Automated Access Request' onclick='submit_auto_request(<?=$user_id?>);'><br><br>
                            </td>
                        
                        <? } else if (1 == $vrss_automated) { ?>
                            <td align=center>
                                <b>You are currently enrolled in VRSS automated uploads.</b><br><br>
                            </td>
                            <? }  ?>
                    </tr>

                </table>


                <form id="auto_form" name="auto_form" method="post">
                    <div id='request_response' name='request_response'></div>

                    <input type="hidden" id="hid_id" name="hid_id" value=<?=$user_id?>>
                    <input type="hidden" id="email_id" name="email_id" value=<?=$email?>>
                    <input type="hidden" id="fname_id" name="fname_id" value=<?=$username?>>
                    <input type="hidden" id="vrss_automated_og" name="vrss_automated_og" value=<?=$username?>>
                </form>
               <center><button type='button' onclick='window.close()'>Close Window</button></center>


        			
        <?php
    }
    }
  else
  { ?>
        <h1 align="center">VRSS Automated Uploads<!-- END: PAGE TITLE --></h1>
        <h2 align="center">Terms and Conditions</h2>
       <table border=1 align=center>
                <tr align=center><td><?=$terms?></td></tr>
        </table>
  <? }


print_footer();

} // end check login

?>