<?php require_once("../db.php"); ?>

<?php require_once("header.php"); ?>

    <div class="container h-100">
		<div class="row justify-content-center align-items-center m-5">
		<h2>Insert dummy sms</h2>
		<p></p>
		<div class="alert alert-primary" role="alert" id="msg-alert" style="display: none;">
		  This is a primary alert—check it out!
		</div>
		<form class="col-6" id="dummy-input-frm">
		
		  <div class="form-group">
			<label for="client_number">Phone number</label>
			<input type="text" class="form-control" id="client_number" name="client_number" placeholder="Phone number">
			<small id="" class="form-text text-muted">Numbers only</small>
		  </div>
		  
		  <div class="form-group">
			<label for="init_message">Inital SMS message</label>
			<textarea class="form-control" id="init_message" name="init_message" rows="3"></textarea>
		  </div>
		  
		  <div class="form-group">
		  <button type="submit" class="btn btn-primary">Send</button>
		  </div>
		  
		</form>
		</div>
	</div>
	
	<!-- end of container -->
	
	<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
	<script src="js/common.js"></script>
	<script>
			$(function(){ 
				$('#dummy-input-frm')[0].reset();
				$("#dummy-input-frm").submit(function(){ // triggers on form submit
					var elid = "#msg-alert";
					
					$(elid).hide();
					var client_number = $("#client_number").val();
					var init_message = $("#init_message").val();
					var insert_form = true;
					if (client_number == '' ) {
						showMsg(elid, "Enter Phone Number", "alert alert-danger");
						insert_form = false;
					} else if (init_message == '') {
						showMsg(elid, "Enter message", "alert alert-danger");
						insert_form = false;
					}
					
					if (insert_form == true) {
						$.ajax({ 
							'url':'ajax/dummy-input-frm.php', 
							'type':'POST', 
							'data':$("#dummy-input-frm").serialize(),
							'success':function(data) { 
								$.trim(data);
								// success 
								if (data == "true") {
									$('#dummy-input-frm')[0].reset();
									showMsg(elid, "Message has been sent", "alert alert-success");
								} else {
									showMsg(elid, data, "alert alert-danger");
								}
							}, 
							'error':function(e) { 
								//failed 
								showMsg(elid, "Failed", "alert alert-danger");
							} 
						}); 
						return false; 
					}
					return false;
				}); 
			}); 
		  </script>

  </body>
  
</html>

