<?php
if(isset($_POST['submit'])){

    //collect form data
    $number=$_POST['number'];
    $gender=$_POST['Gender'];
    $age=$_POST['age'];
    $District=$_POST['District'];
    $Area=$_POST['Area'];
    $Community=$_POST['Community'];
    $Qualification=$_POST['Qualification'];
    $Job=$_POST['Job'];
    $Pleasure=$_POST['Pleasure'];
    $Feeling=$_POST['Feeling'];
    $Trouble=$_POST['Trouble'];
    $Tired=$_POST['Tired'];
    $Appetite=$_POST['Appetite'];
    $Failure=$_POST['Failure'];
    $Betteroff=$_POST['Betteroff'];
    $Concentrating=$_POST['Concentrating'];
    $Moving=$_POST['Moving'];
    $Affected=$_POST['Affected'];
    $Without=$_POST['Without'];
    $Express=$_POST['Express'];
    $Phone=$_POST['Phone'];
    $Time=$_POST['Time'];
    $Help=$_POST['Help'];


    
    //if no errors carry on
    if(!isset($error)){

        # Title of the CSV
        $Content = "Regno,Gender,Age,District,Area,Community,Qualification,Job,PleasureDoing,Feeling,Troublefeeling,TiredEnergy,EatingHabit,FaliureOrFamily,BetterOffDead,TroubleCon,MovingNspeaking,HowAffected,WithoutFamily,ExpressFeelings,PhoneUse,TimeUse,HelpYou\n";


        //set the data of the CSV
        $Content .= "$number,$gender,$age,$District,$Area,$Community,$Qualification,$Job,$Pleasure,$Feeling,$Trouble,$Tired,$Appetite,$Failure,$Betteroff,$Concentrating,$Moving,$Affected,$Without,$Express,$Phone,$Time,$Help\n";

        # set the file name and create CSV file
        $FileName = "formdata-".date("d-m-y-h:i:s").".csv";
        header('Content-Type: application/csv'); 
        header('Content-Disposition: attachment; filename="' . $FileName . '"'); 
        echo $Content;
        exec('C:\\"Program Files"\\R\\R-3.5.1\\bin\\Rscript.exe C:\xampp\htdocs\predict\Rscript.R ');
        exit();
    }
}

//if their are errors display them
if(isset($error)){
    foreach($error as $error){
        echo "<p style='color:#ff0000'>$error</p>";
    }
}
?> 

<form action='' method='post'>


  <h3>Enter your Registration Number</h3>
<input type="text" name="number">

<h2>Gender </h2>
  <input type="radio" name="Gender" value="Male">Male<br>
  <input type="radio" name="Gender" value="Female">Female<br>
  <input type="radio" name="Gender" value="Others">Others<br>
  
  <h3>Age</h3>
<input type="text" name="age">

  <h2>Select your district(Permanent)</h2>
  <input type="radio" name="District" value="East">East<br>
  <input type="radio" name="District" value="West">West<br>
  <input type="radio" name="District" value="North">North<br>
  <input type="radio" name="District" value="South">South<br>
  <input type="radio" name="District" value="Rest of India">Rest of India<br>

  <h2>Select your area</h2>
  <input type="radio" name="Area" value="Rural">Rural<br>
  <input type="radio" name="Area" value="West">Urban<br>


  <h2>Select your community</h2>
  <input type="radio" name="Community" value="ST">ST<br>
  <input type="radio" name="Community" value="SC">SC<br>
  <input type="radio" name="Community" value="OBC(state)">OBC(state)<br>
  <input type="radio" name="Community" value="OBC(central)">OBC(central)<br>
  <input type="radio" name="Community" value="General">General<br>
  <input type="radio" name="Community" value="MBC">MBC<br>

  
<h2>Select Your Qualification</h2>
  <input type="radio" name="Qualification" value="Matriculation">Matriculation<br>
  <input type="radio" name="Qualification" value="Senior Secondary">Senior Secondary<br>
  <input type="radio" name="Qualification" value="Graduation">Graduation<br>
  <input type="radio" name="Qualification" value="Post-Graduation">Post-Graduation<br>
  <input type="radio" name="Qualification" value="None">None<br>


  <h2>Select Your Job type</h2>
  <input type="radio" name="Job" value="Government">Government<br>
  <input type="radio" name="Job" value="Semi-Government">Semi-Government<br>
  <input type="radio" name="Job" value="Private">Private<br>
  <input type="radio" name="Job" value="Self-employed">Self-employed<br>
  <input type="radio" name="Job" value="Unemployed">Unemployed<br>
  <input type="radio" name="Job" value="Student">Student<br>

  <h2>please select the option below</h2>
<hr>
<h2>In the past 20 days how often have you have</h2>

<h2>Little interest or pleasure in doing things</h2>
  <input type="radio" name="Pleasure" value=" Not at all"> Not at all<br>
  <input type="radio" name="Pleasure" value="Sometimes">Sometimes<br>
  <input type="radio" name="Pleasure" value="Several days">Several days<br>
  <input type="radio" name="Pleasure" value="More than half the days">More than half the days<br>
  <input type="radio" name="Pleasure" value="Nearly everyday">Nearly everyday<br>

  <h2>Feeling down, depressed, or hopeless</h2>
  <input type="radio" name="Feeling" value=" Not at all"> Not at all<br>
  <input type="radio" name="Feeling" value="Sometimes">Sometimes<br>
  <input type="radio" name="Feeling" value="Several days">Several days<br>
  <input type="radio" name="Feeling" value="More than half the days">More than half the days<br>
  <input type="radio" name="Feeling" value="Nearly everyday">Nearly everyday<br>

  <h2>Trouble in falling asleep or sleeping too much</h2>
  <input type="radio" name="Trouble" value=" Not at all"> Not at all<br>
  <input type="radio" name="Trouble" value="Sometimes">Sometimes<br>
  <input type="radio" name="Trouble" value="Several days">Several days<br>
  <input type="radio" name="Trouble" value="More than half the days">More than half the days<br>
  <input type="radio" name="Trouble" value="Nearly everyday">Nearly everyday<br>

  <h2>Feeling tired or having little energy</h2>
  <input type="radio" name="Tired" value=" Not at all"> Not at all<br>
  <input type="radio" name="Tired" value="Sometimes">Sometimes<br>
  <input type="radio" name="Tired" value="Several days">Several days<br>
  <input type="radio" name="Tired" value="More than half the days">More than half the days<br>
  <input type="radio" name="Tired" value="Nearly everyday">Nearly everyday<br>

  <h2>Poor appetite or overeating</h2>
  <input type="radio" name="Appetite" value=" Not at all"> Not at all<br>
  <input type="radio" name="Appetite" value="Sometimes">Sometimes<br>
  <input type="radio" name="Appetite" value="Several days">Several days<br>
  <input type="radio" name="Appetite" value="More than half the days">More than half the days<br>
  <input type="radio" name="Appetite" value="Nearly everyday">Nearly everyday<br>

  <h2>Feeling bad about yourself - or that you are a failure or have let yourself or your family down</h2>
  <input type="radio" name="Failure" value=" Not at all"> Not at all<br>
  <input type="radio" name="Failure" value="Sometimes">Sometimes<br>
  <input type="radio" name="Failure" value="Several days">Several days<br>
  <input type="radio" name="Failure" value="More than half the days">More than half the days<br>
  <input type="radio" name="Failure" value="Nearly everyday">Nearly everyday<br>

  <h2>Thoughts that you would be better off dead, or of hurting yourself</h2>
  <input type="radio" name="Betteroff" value=" Not at all"> Not at all<br>
  <input type="radio" name="Betteroff" value="Sometimes">Sometimes<br>
  <input type="radio" name="Betteroff" value="Several days">Several days<br>
  <input type="radio" name="Betteroff" value="More than half the days">More than half the days<br>
  <input type="radio" name="Betteroff" value="Nearly everyday">Nearly everyday<br>

  <h2>Trouble concentrating on things, such as reading the newspaper or watching television</h2>
  <input type="radio" name="Concentrating" value=" Not at all"> Not at all<br>
  <input type="radio" name="Concentrating" value="Sometimes">Sometimes<br>
  <input type="radio" name="Concentrating" value="Several days">Several days<br>
  <input type="radio" name="Concentrating" value="More than half the days">More than half the days<br>
  <input type="radio" name="Concentrating" value="Nearly everyday">Nearly everyday<br>

  <h2>How often did you feel that you moving or speaking so slowly, or the opposite, being so restless, that other people could have noticed?</h2>
  <input type="radio" name="Moving" value=" Not at all"> Not at all<br>
  <input type="radio" name="Moving" value="Sometimes">Sometimes<br>
  <input type="radio" name="Moving" value="Several days">Several days<br>
  <input type="radio" name="Moving" value="More than half the days">More than half the days<br>
  <input type="radio" name="Moving" value="Nearly everyday">Nearly everyday<br>

  <h2>How have the above problems(if any) affected you at work, home, school or with other person</h2>
  <input type="radio" name="Affected" value=" Not at all"> Not at all<br>
  <input type="radio" name="Affected" value="Sometimes">Sometimes<br>
  <input type="radio" name="Affected" value="Several days">Several days<br>
  <input type="radio" name="Affected" value="More than half the days">More than half the days<br>
  <input type="radio" name="Affected" value="Nearly everyday">Nearly everyday<br>

  <h2>Thoughts that you would be better off without family or parent or feel like hurting them</h2>
  <input type="radio" name="Without" value=" Strongly Disagree"> Strongly Disagree<br>
  <input type="radio" name="Without" value="Disagree">Disagree<br>
  <input type="radio" name="Without" value="Agree">Agree<br>
  <input type="radio" name="Without" value="Strongly Agree">Strongly Agree<br>


  <h2>Do you feel like talking to people or express your feeling with other?</h2>
  <input type="radio" name="Express" value=" Never"> Never<br>
  <input type="radio" name="Express" value="Sometimes">Sometimes<br>
  <input type="radio" name="Express" value="Most of the times">Most of the times<br>
  <input type="radio" name="Express" value="Frequently">Frequently<br>

  <h2>In 24 hrs, what you mostly use your phone for</h2>
  <input type="radio" name="Phone" value=" E-Learning"> E-Learning<br>
  <input type="radio" name="Phone" value="Social Networking">Social Networking<br>
  <input type="radio" name="Phone" value="Gaming">Gaming<br>
  <input type="radio" name="Phone" value="Entertainment(Video, Music, Surfing)">Entertainment(Video, Music, Surfing)<br>

  <h2>On average in the span of 24 hours how many hours do you use your phone</h2>
  <input type="radio" name="Time" value=" 0-2 Hours">0-2 Hours<br>
  <input type="radio" name="Time" value="3-5 Hours">3-5 Hours<br>
  <input type="radio" name="Time" value="6-8 Hours">6-8 Hours<br>
  <input type="radio" name="Time" value="Above 8 Hours">Above 8 Hours<br>

  <h2>Do you believe that this survey will help you ?</h2>
  <input type="radio" name="Help" value=" Disagree">Disagree<br>
  <input type="radio" name="Help" value="Somewhat Agree">Somewhat Agree<br>
  <input type="radio" name="Help" value="Agree">Agree<br>
  <input type="radio" name="Help" value="Strongly Agree">Strongly Agree<br>


  
<p><input type='submit' name='submit' value='Submit'></p> 
</form>