<?php
$msg='';

$conn=new MMySQLi("localhost","karan_live","Sailor@123!","karan_live");  //Live Rishta DB


if (isset($_POST['submit'])) { 
    $name = $_POST['name'];

    $sql = "INSERT INTO source (name) VALUES ('$name')";
    if (mysqli_query($conn, $sql)) {
        header('Location: manage-source.php');
        exit();
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
}



?>
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="">
	<meta name="author" content="">


	<title>Add - Rishta Depot </title>
	<?php include('./include/meta.php'); ?>

</head>
<?php include('./include/header.php'); ?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<div class="container-full">
		<!-- Content Header (Page header) -->
		<div class="content-header">
			<div class="d-flex align-items-center">
				<div class="me-auto">
					<h4 class="page-title">Forms</h4>
					<div class="d-inline-block align-items-center">
						<nav>
							<ol class="breadcrumb">
								<li class="breadcrumb-item"><a href="#"><i class="mdi mdi-home-outline"></i></a></li>
								<li class="breadcrumb-item" aria-current="page">Add source/li>
								<li class="breadcrumb-item active" aria-current="page">Forms</li>
							</ol>
						</nav>
					</div>
				</div>

			</div>
		</div>

		<!-- Main content -->
		<section class="content">
			<div class="row">
				<div class="col-12">
					<div class="box">
						<div class="box-header with-border">
							<h3 class="box-title">Add</h3>
							<?php
					if(trim($msg)!=null)
					{
						?>
							<div class='row'>
								<div class='col-md-12'>
									<div class="alert alert-success errormessage" id="errormessage">
										<strong><?php echo $msg ?></strong>
									</div>
								</div>
							</div>
						<?php
					}
					?>
						</div>
						<!-- /.box-header -->
							<form action="#" method="post" enctype="multipart/form-data">
							<div class="box-body">
								<div class="row">
								
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Name</label>
												<input type="text" placeholder="Name" maxlength="50" id="name" name="name" class="form-control" value="<?php if(isset($_POST['txtName']))echo $_POST['txtName']; ?>"/>
										</div>
									</div>
								</div>
						
							
								<div class="box-footer">
									     <button type="submit" class="btn btn-primary" name="submit">Add</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</section>
		<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>



<script>
		
		function saveuser()
		{
			var txtName=$('#txtName').val();
			var txtPassword=$('#txtPassword').val();
			var txtConfirmPassword=$('#txtConfirmPassword').val();
			var txtEmailId=$('#txtEmailId').val();
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			
			if($.trim(txtName).length==0 || $.trim(txtPassword).length==0 || $.trim(txtConfirmPassword).length==0 || $.trim(txtEmailId).length==0)
			{
				alert("Please fill all the required fields.");
				return false;
			}
			else if(emailReg.test(txtEmailId) == false)
			{
				alert("Enter the valid email");
				return false;
			}
			else if(txtPassword!=txtConfirmPassword)
			{
				alert("Enter The Correct Passwords");
				return false;
			}
			else if((txtConfirmPassword.length < 8 || txtConfirmPassword.length>20) || (!/\d/.test(txtConfirmPassword)) || (!/[a-z]/.test(txtConfirmPassword)) || (!/[A-Z]/.test(txtConfirmPassword)) || (!/[!@#$%\^&*(){}[\]<>?/|\-]/.test(txtConfirmPassword)))
			{
				//alert("Enter The Correct Password Format.");
				$msg="Password must be 8-20 characters<br/>";
				$msg+="Password must contain 1 digit<br/>";
				$msg+="Password must contain 1 lower case character<br/>";
				$msg+="Password must contain 1 upper case character<br/>";
				$msg+="Password must contain 1 special character<br/>";
				$('.errormessage').html(msg);
				return false;
			}
			else
			{
				return confirm('Are You Sure?');
			}
		}
		
		function back() 
		{
			var c=confirm('Are You Sure?');
			if(c==true)
			{
				window.location="manage-users.php";
			}
		}  	
		
		function isDecimal(evt, element) 
		{
			var charCode = (evt.which) ? evt.which : event.keyCode
			if ((charCode != 46 || $(element).val().indexOf('.') != -1) &&      // “.” CHECK DOT, AND ONLY ONE.
				(charCode < 48 || charCode > 57))
				return false;
			return true;
		}  	
		function isNumber(evt, element) 
		{
			var charCode = (evt.which) ? evt.which : event.keyCode
			if ((charCode < 48 || charCode > 57))
				return false;
			return true;
		}   
		$(document).ready(function() {
			$('body').on("keypress",'#txtExperience',function(){  
				return isDecimal(event, this)
			});
			$('body').on("keypress",'#txtCredits',function(){  
				return isNumber(event, this)
			});	
			$('#txtName').keypress(function (e) 
			{
				var regex = new RegExp("^[a-zA-Z ]+$");
				var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
				if (regex.test(str)) {
					return true;
				}

				e.preventDefault();
				return false;
			});
			//$('input').bind("cut copy paste",function(e) {
			//	e.preventDefault();
			//});
		});	
	</script>
		<?php include('./include/footer.php'); ?>