<?php
session_start();
include('connectdb.php'); 
include("side_nav.php"); 
include("top_nav.php"); 

if(isset($_POST['submit'])){
	$loyalty_id = mysqli_real_escape_string($con, $_POST['loyalty_id']);
    $test_id = mysqli_real_escape_string($con, $_POST['test_id']);
    $test_report = mysqli_real_escape_string($con, $_POST['test_report']);
    $test_date = mysqli_real_escape_string($con, $_POST['test_date']) ;
	$date_created = date("Y-m-d h:i:sa");

    $query = mysqli_query($con, "INSERT INTO testreport (loyalty_id, test_id, test_date, test_report, date_created)  
					   VALUES ('$loyalty_id', '$test_id', '$test_date', '$test_report', '$date_created')");
					   
	if($query == true){
		 $output = '
					<div class="alert alert-success alert-dismissible fade in">
					    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
						<span class="glyphicon glyphicon-info-sign"></span> Report successfully created 
					</div>
				  ';
	  }else{
		  $output = '
	            <div class="alert alert-danger">
				    <span class="glyphicon glyphicon-info-sign"></span> Failed to create report.
                </div>
	          ';
	  }
}
?>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
            <div class="clearfix"></div>
            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Create test report <small></small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                          <li><a href="#">Settings 1</a>
                          </li>
                          <li><a href="#">Settings 2</a>
                          </li>
                        </ul>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <br />
                    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST" class="form-horizontal form-label-left">

					  <div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							  <?php echo $output;  ?>
						</div>
					  </div>
					  
					  <div class="form-group">
					    <label class="control-label col-md-3 col-sm-3 col-xs-12">Patient Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select name="loyalty_id" required="required" class="form-control col-md-7 col-xs-12 select2">
						    <option value=""> </option>
							<?php $sql = mysqli_query($con, "SELECT * FROM loyalty  ");  
						       while($row = mysqli_fetch_array($sql)):
						    ?>
						     <option value="<?php echo $row['loyalty_id']?> "> <?php echo $row['first_name'] .' '.$row['last_name'].' '.$row['phone']  ?></option>
						    <?php endwhile;  ?>
                          </select>
                        </div>
                      </div>
					  
					  <div class="form-group">
					    <label class="control-label col-md-3 col-sm-3 col-xs-12">Select test <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select name="test_id" required="required" class="form-control col-md-7 col-xs-12 select2">
						    <option value=""> </option>
							<?php $sql = mysqli_query($con, "SELECT * FROM labtest  ");  
						       while($row = mysqli_fetch_array($sql)):
						    ?>
						     <option value="<?php echo $row['test_id']?> "> <?php echo $row['test_name']  ?></option>
						    <?php endwhile;  ?>
                          </select>
                        </div>
                      </div>
					  
					  <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Date test was carried out <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="datetime-local" name="test_date" required="required" class="form-control col-md-7 col-xs-12">
                        </div>
                      </div>
					  
					  <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Test report <span class="required">*</span>
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                          <textarea name="test_report" class="form-control col-md-7 col-xs-12"></textarea>
                        </div>
                      </div>
					  
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                          <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                        </div>
                      </div>

                    </form>
                  </div>
                </div>
              </div>
            </div>
<?php include("footer.php"); ?>         
	<!-- Include Editor JS files. -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.7.3/js/froala_editor.pkgd.min.js"></script>
 
    <!-- Initialize the editor. -->
    <script> $(function() { $('textarea').froalaEditor() }); </script>
<script>
    $('.select2').select2();
</script>