<?php
$msg='';

include("include/settings.php");
//include("checksession.php");

if(isset($_POST['btnSaveMember']))
{
	$_POST["txtType"]='sales_exec';
	if(trim($_POST["txtEmailId"])!=null && trim($_POST["txtName"])!=null && trim($_POST["txtType"])!=null && (trim($_POST["txtPassword"])==trim($_POST["txtConfirmPassword"])))
	{	
		$my_user_email=strtolower($_POST["txtEmailId"]);
		$usermaster=$mysqli->prepare("select count(*) from cdi_usermaster where user_email_id=?");
		$usermaster->bind_param("s",$my_user_email);
		$usermaster->execute();
		$usermaster->bind_result($count);
		$usermaster->fetch();
		$usermaster->close();

		if($count>0)
		{
			$msg="Email Id Already Exists";
		}
		else
		{
			$password = $_POST["txtPassword"];
			if ((strlen($password) < 8 || strlen($password) > 20) || (!preg_match("#[0-9]+#",$password)) || (!preg_match("#[A-Z]+#",$password)) || (!preg_match("#[a-z]+#",$password))  || (!preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $password)))
			{
				$msg= "Password Must Contain 8-20 Characters! with At Least 1 Number, 1 uppercase,1 lowercase and 1 special character.";
			}
			else
			{
				$thedate=$thisdate;
				$md5password=md5('cybeRintelligencE'.$_POST['txtPassword'].$thedate);
				
				$usermaster=$mysqli->prepare("INSERT INTO cdi_usermaster(user_email_id, user_password, user_full_name, user_type, user_status, user_creationdate,user_added_by, extension, extension3, country) VALUES (?,?,?,?,?,?,?,?,?,?)");
				$usermaster->bind_param("ssssisisss",$my_user_email,$md5password,$_POST['txtName'],$_POST['txtType'],$_POST['rbtnStatus'],$thedate,$_SESSION['userId'],$_POST['extension'],$_POST['extension3'],$_POST['country']);
				$usermaster->execute();
				$usermaster->close();
		
				
				$mailBody='<html>
						<body style="background-color:#ddd; padding:0; margin:0; font-family:Verdana, Geneva, sans-serif; font-size:14px;">
							<section align="center">
								<div style="width:100%; max-width:710px; margin:auto; background:#fff; text-align: left;">
									<table style="width:100%;" border="0" cellspacing="0">
										<tr style="background-color:#cd5547;">
											<td style="width:30%; padding:10px 0 10px 35px;">
												<img src="'.$newsletterurl.'images/mail-logo.png" style="width:100%; max-width:68px; height:68px;">
											</td>
											<td style="width:70%; padding:10px 35px 10px 0 ;">
												<p style="text-align:right; color:#fff;">        
													<strong style="font-size:20px;">24x7 Support</strong><br/>
													+91-9888-555-182<br/>+91-9888-555-180<br/>
													<span style="color:#fff!important">info<span>@</span>cyberintelligence<span>.</span>in</span>
												</p>
											</td>
										</tr>
									</table>
									<div style="margin-bottom:30px;">
										<p style="padding: 40px 30px 10px;">
											Hi '.$_POST['txtName'].', 
											<br/><br/>
											Welcome and Hope you are doing great!!
											<br/><br/>
											We are pleased you will be joining us in our produce division and anticipate your continued excellent work.<br/><br/>
											Your login link is: <b>'.$executive_link.'</b><br/><br/>
											Your login Email is: <b>'.$my_user_email.'</b><br/><br/>
											Your password is: <b>'.$_POST['txtPassword'].'</b>
											
											<br/><br/>
											All the Best. 
											<br/>

											Thanks 
											TEAM CDI ! 
											<br/><br/><br/> 
										</p>
									</div>

									<div style="background-color:#333; padding:40px 0;">
										<p style="text-align:center; color:#fff; font-size:12px; line-height:20px;">
											<a href="https://www.facebook.com/cyberintelligence.in"><img src="'.$newsletterurl.'images/fb.png" style="margin-right:5px; margin-bottom:5px;"></a>
											<a href="https://twitter.com/@cdi_consulting"><img src="'.$newsletterurl.'images/twitter.png" style="margin-right:5px; margin-bottom:5px;"></a>
											<a href="https://www.linkedin.com/in/cyber-defence-intelligence-cdi-consulting-158618a7"><img src="'.$newsletterurl.'images/linked-in.png" style="margin-bottom:5px;"></a>
											<br/>
											Contact Address :  Rishta Dipot<br/>All rights reserved
										</p>
									</div>
								</div>    
							</section>	
						</body>
					</html>';
					


			}
		}
	}
	else
	{
		$msg="Please enter all the fields correctly.";
	}
}

?>
<!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 New User - 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 Users</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 Users</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">Email Id</label>
												<input type="text" placeholder="Email Id" id="txtEmailId" name="txtEmailId" class="form-control" value="<?php if(isset($_POST['txtEmailId']))echo $_POST['txtEmailId']; ?>"/>
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Name</label>
												<input type="text" placeholder="Name" maxlength="50" id="txtName" name="txtName" class="form-control" value="<?php if(isset($_POST['txtName']))echo $_POST['txtName']; ?>"/>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Password </label>
											<input type="password" maxlength="50" id="txtPassword" name="txtPassword" class="form-control" placeholder="Password"/>
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Confirm Password</label>
											<input type="password" maxlength="50" id="txtConfirmPassword" name="txtConfirmPassword" class="form-control" placeholder="Password"/>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Indian Dialer Extension</label>
											<input type="text" maxlength="200" id="extension" name="extension" class="form-control" placeholder="Extension ID" />
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">3cx Extension ID</label>
												<input type="text" maxlength="200" id="extension3" name="extension3" class="form-control" placeholder="3cx Extension ID"/>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Country</label>
												<select id="ddlLeadType" name="country" class="form-select">
                            <option value="" selected="">Country</option>
                            <option value="India">India</option>
                            <option value="Canada">Canada</option>
                                   </select>
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label class="form-label">Status</label>
											<div class="c-inputs-stacked">
										
												
													<input type="radio" class="form-check-input" value="1" id="rbtnActive" name="rbtnStatus" checked="checked" /><label for="rbtnActive" class="form-check-label">Active</label>
													<input type="radio" class="form-check-input" value="0" id="rbtnInactive" name="rbtnStatus"  /><label for="rbtnInactive" class="form-check-label">Inactive</label>
												
											
												
												<!-- Example single danger button -->
									<!--div class="md-6">
										<div class="form-group">
											<label class="form-label">Users</label>
											<div class="c-inputs-stacked">
											<input class="form-check-input" type="radio" name="userType" id="flexRadioDefault3">
												<label class="form-check-label" for="flexRadioDefault3">
													Manager
												</label>
												<input class="form-check-input" type="radio" name="userType" id="flexRadioDefault4">
												<label class="form-check-label" for="flexRadioDefault4">
													Executive
												</label>
												<input class="form-check-input" type="radio" name="userType" id="flexRadioDefault5">
												<label class="form-check-label" for="flexRadioDefault5">
													Team Leader
												</label>
											</div>
										</div>
									</div-->
									
												<!--div class="btn-group">
													<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
														Manager List
													</button>
													<div class="dropdown-menu">
														<a class="dropdown-item" href="#">Manager 1</a>
														<a class="dropdown-item" href="#">Manager 2</a>
														<a class="dropdown-item" href="#">Manager 3</a>

													</div>
												</div>
												<div class="btn-group">
													<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
														Executive List
													</button>
													<div class="dropdown-menu">
														<a class="dropdown-item" href="#">Executive 1</a>
														<a class="dropdown-item" href="#">Executive 2</a>
														<a class="dropdown-item" href="#">Executive 3</a>

													</div>
												</div>
												<div class="btn-group">
													<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
														Team Leader List
													</button>
													<div class="dropdown-menu">
														<a class="dropdown-item" href="#">Team Leader 1</a>
														<a class="dropdown-item" href="#">Team Leader 2</a>
														<a class="dropdown-item" href="#">Team Leader 3</a>

													</div>
												</div-->
											</div>
										</div>
									</div>
								</div>
								<div class="box-footer">
									<!--button type="submit" class="btn btn-primary">
										<i class="ti-save-alt"></i> Save Sales Executive</button-->
										<input type="submit" id="btnSaveMember" name="btnSaveMember" value="Save Sales Executive" class="btnCustom" onclick="return saveuser()"/> 
									<!--button type="button" class="btn btn-warning me-1">
										<i class="ti-trash"></i> Cancel</button-->
										<input type="button" id="btnBack" name="btnBack" value="Go Back" class="btnCustom" onclick="return back()"/>
								</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'); ?>