register.php
<?php
if(!session_start()){
session_start();
}
include "include/connect.php";
include "include/functions.php";
$error = '';
if (!empty($_SESSION['token'])) {
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register Page</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<style type="text/css" media="screen">
li { list-style: none}
.hide-password { display: none }
.form-control.password { display: inline-block; float: left; width: 90%;}
</style>
<style type="text/css" media="screen">
#mydiv {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: 10000;
background-color: white;
opacity: 0.8;
display: none;
}
.ajax-loader {
position: absolute;
left: 50%;
top: 50%;
margin-left: -32px; /* -1 * image width / 2 */
margin-top: -32px; /* -1 * image height / 2 */
display: block;
}
.errorBox { /* for the error input text fields */
border: 1px solid red;
}
</style>
<script async src="https://www.google.com/recaptcha/api.js?render=6LfrBrMfAAAAAJtiXF1gugzCcuwHazIBmvqwa2qH"></script>
</head>
<body class="gray-bg">
<div id="mydiv"> <img src="img/loading.gif" class="ajax-loader"/> </div>
<div class="navbar navbar-dark bg-dark">
<div class="container">
<a href="" title="" class="navbar-brand">OPD Management Application</a>
</div>
</div>
<div class="row">
<div class="container">
<div class="row">
<div class="col-md-6">
<h3>Register your Clinic here</h3>
</div>
<div class="col-md-6">
<span>Allready have account? <a href="login.php" class="btn btn-primary">Login Here..</a></span>
</div>
</div>
<hr>
<div class=""><h3 class="m-t-none m-b">Create a new clinic OPD Management System Account</h3>
<p>Add fields and click on Save for save it.</p>
<span id="msgdisplay"></span>
<form method="post" class="form-horizontal" id="editform_new" name="editform_new">
<div class="form-group">
<label class="col-sm-2 control-label">Clinic Name <span class="red">*</span></label>
<div class="col-sm-2">
<input name="clinicName" id="clinicName" type="text" class="form-control" placeholder="Enter Clinic Name" required="required">
<h5 id="namecheck" style="color: red;">Please fill the Fullname</h5>
</div>
<label class="col-sm-2 control-label">Doctor Name <span class="red">*</span></label>
<div class="col-sm-2">
<input name="doctorName" id="doctorName" type="text" class="form-control" placeholder="Enter Doctor Name" required="required">
<h5 id="drnamecheck" style="color: red;">Please fill the Doctor name</h5>
</div>
<label class="col-sm-2 control-label">Last Name <span class="red">*</span></label>
<div class="col-sm-2">
<input name="lname" id="lname" type="text" class="form-control" placeholder="Enter Surname" required="required">
<h5 id="lnamecheck" style="color: red;">Please fill the Last name</h5>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label">Mobile Number <span class="red">*</span></label>
<div class="col-sm-2">
<input name="phone1" id="phone1" type="text" class="form-control" placeholder="Enter Mobile Number" required="required" minlength="10" maxlength="12" >
<h5 id="mobilecheck" style="color: red;">Please fill the Mobile Number</h5>
</div>
<label class="col-sm-2 control-label">Mobile Number 2</label>
<div class="col-sm-2"><input type="text" name="phone2" id="phone2" class="form-control" placeholder="Enter Mobile Number" ></div>
<label class="col-sm-2 control-label">Land Line Number</label>
<div class="col-sm-2"><input type="text" name="phone3" id="phone3" class="form-control" placeholder="Enter Land Line Number" ></div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label" for="emailid" pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}">Email Id as Username<span class="red">*</span></label>
<div class="col-sm-2">
<input type="text" name="emailid" id="emailid" class="form-control" placeholder="Enter Email ID" >
<h5 id="emailvalid" style="color: red;">Your email must be a valid email</h5>
</div>
<label class="col-sm-2 control-label">Password <span class="red">*</span>
</label>
<div class="col-sm-2"><input name="password" id="password" type="password" class="form-control" placeholder="Enter Password" required="required" autocomplete="new-password" minlength="6">
<span toggle="#password-field" class="fa fa-fw fa-eye field_icon toggle-password"></span>
<label class="form-label" for="password">Password (Minimum 6 characters)</label>
<p id="passcheck" style="color: red;">Please Fill the password</p>
</div>
<label class="col-sm-2 control-label">Password Again<span class="red">*</span>
</label>
<div class="col-sm-2"><input name="password2" id="password2" type="password" class="form-control" placeholder="Enter Password again" required="required">
<span toggle="#password-field" class="fa fa-fw fa-eye field_icon toggle-password2"></span>
<h5 id="conpasscheck" style="color: red;">**Password didn't match</h5>
<span id="msgp"></span>
</div>
</div>
<span class="col-sm-12" id="emailmsg"></span>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label class="col-sm-2 control-label">Your Degree</label>
<div class="col-sm-2"><input type="text" name="degree" id="degree" class="form-control" placeholder="Enter your degrees" ></div>
<label class="col-sm-2 control-label" title="You can add Doctors and Staff"> Add Staff <span class="red">*</span></label>
<div class="col-sm-2">
<select name="addStaff" id="addStaff">
<option disabled title="You can not add unlimited staff in demo">Unlimited Staff </option>
<option value="1">1</option>
<option value="2" selected="selected">2</option>
</select>
</div>
<label class="col-sm-2 control-label"> Address <span class="red">*</span></label>
<div class="col-sm-2">
<input type="text" name="address" id="address" class="form-control" placeholder="Enter Address" >
<h5 id="addressCheck" style="color: red;">Please fill the Address</h5>
</div>
</div>
<div id="usernmmsg"></div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-1 col-sm-offset-2">
<!-- <input type="button" name="cancel" class="btn btn-white" value="Cancel" > -->
<a class="btn btn-white" href="login.php" title="">Cancel</a>
</div>
<div class="col-sm-1"></div>
<div class="col-sm-2 col-sm-offset-1">
<button class="btn btn-primary" type="button" onclick="saveuser()">Register Clinic</button>
</div>
</div>
<div class="hr-line-dashed"></div>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
</form>
</div>
</div>
<div class="col-sm-12">
<span id="msg"></span>
</div>
</div>
<?php include "footer.php"; ?>
<!-- Mainly scripts -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function saveuser(){
var clinicName = $('#clinicName').val();
var doctorName = $('#doctorName').val();
var lname = $('#lname').val();
var phone1 = $('#phone1').val();
var phone2 = $('#phone2').val();
var phone3 = $('#phone3').val();
var emailid = $('#emailid').val();
var email = document.getElementById('emailid');
//var uname = $('#uname').val();
var password1 = $('#password').val();
var password2 = $('#password2').val();
var addStaff = $('#addStaff').val();
var address = $('#address').val();
var degree = $('#degree').val();
let clinicnameCheck = false;
let doctorNameCheck = false;
let lnameCheck = false;
let phone1Check = false;
let emailidCheck = false;
let password1Check = false;
let password2Check = false;
let addressCheck = false;
if (clinicName.length == '' ) {
$('#namecheck').show();
clinicnameCheck = false;
}else{
$('#namecheck').hide();
clinicnameCheck = true;
}
if (doctorName.length == '' ) {
$('#drnamecheck').show();
doctorNameCheck = false;
}else{
$('#drnamecheck').hide();
doctorNameCheck = true;
}
if (lname.length == '' ) {
$('#lnamecheck').show();
lnameCheck = false;
}else{
$('#lnamecheck').hide();
lnameCheck = true;
}
if (phone1.length < 10 ) {
$('#mobilecheck').show();
phone1Check = false;
}else{
$('#mobilecheck').hide();
phone1Check = true;
}
if (emailid.length < 5 ) {
$('#emailvalid').show();
emailidCheck = false;
}else{
var regex = /^([_\-\.0-9a-zA-Z]+)@([_\-\.0-9a-zA-Z]+)\.([a-zA-Z]){2,7}$/;
var s = email.value;
if(regex.test(s)){
email.classList.remove('is-invalid');
emailError = true;
$('#emailvalid').hide();
emailidCheck = true;
//CheckUserEmailID();
}
else{
email.classList.add('is-invalid');
$('#emailvalid').show();
emailError = false;
emailidCheck = false;
}
}
if (password1.length == '' ) {
$('#passcheck').show();
password1Check = false;
}else{
$('#passcheck').hide();
password1Check = true;
}
if (clinicnameCheck == true && doctorNameCheck == true && lnameCheck == true && phone1Check == true && emailidCheck == true && password1Check == true ) {
//var formData = new FormData($('#addform')[0]);
$.ajax({
type: "POST",
url: "ajax.php",
data: 'insertclinicName='+clinicName+'&doctorName='+doctorName+'&lname='+lname+'&phone1='+phone1+'&phone2='+phone2+'&phone3='+phone3+'&emailid='+emailid+'&password1='+password1+'&password2='+password2+'&addStaff='+addStaff+'&address='+address+'°ree='+degree,
//data: formData,
beforeSend: function(){
$('#mydiv').show();
$("#usernmmsg").html('');
$("#msgdisplay").html('');
},
success: function(data){
$('#mydiv').hide();
if(data == 1)
{
$("#msgdisplay").html("<div class='col-md-12'><div class='alert alert-success fade in'><a class='close' title='close' aria-label='close' data-dismiss='alert' href='#'>×</a><strong>Done! </strong> You are registered with us. Check Email for more details.</div> </div>");
$("#emailmsg").html('');
$("#emailmsg").html("<div class='col-md-12'><div class='alert alert-success fade in'><a class='close' title='close' aria-label='close' data-dismiss='alert' href='#'>×</a><strong>Done! </strong> You are registered with us. Check Email for more details.</div> </div>");
//$("#msgdisplay").fadeTo(2000, 500).slideUp(500, function(){
// $("#msgdisplay").slideUp(500);
//});
//$("#content").load("show_role.php");
//setTimeout(function(){ location.reload(); }, 3000);
//location.reload();
}else{
$("#msgdisplay").html("<div class='col-md-12'><div class='alert alert-danger fade in'><a class='close' title='close' aria-label='close' data-dismiss='alert' href='#'>×</a><strong>Error! </strong> Data Not Saved. </div> </div>");
//$("#msgdisplay").fadeTo(2000, 500).slideUp(500, function(){
// $("#msgdisplay").slideUp(500);
//});
//location.reload();
}
}
});
}
}
$(document).on('click', '.toggle-password', function() {
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $("#password");
input.attr('type') === 'password' ? input.attr('type','text') : input.attr('type','password')
});
$(document).on('click', '.toggle-password2', function() {
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $("#password2");
input.attr('type') === 'password' ? input.attr('type','text') : input.attr('type','password')
});
$(document).ready(function(){
$('#emailvalid').hide();
$('#passcheck').hide();
$('#conpasscheck').hide();
$('#namecheck').hide();
$('#drnamecheck').hide();
$('#lnamecheck').hide();
$('#mobilecheck').hide();
$("#password2").keyup(function(){
if ($("#password").val() != $("#password2").val()) {
//$("#msgp").html("Password do not match").css("color","red");
$('#conpasscheck').show();
}else{
//$("#msgp").html("Password matched").css("color","green");
$('#conpasscheck').hide();
}
});
var email = document.getElementById('emailid');
$('#emailid').keyup(function () {
validateEmail();
});
function validateEmail() {
//email.addEventListener('blur', ()=>{
var regex = /^([_\-\.0-9a-zA-Z]+)@([_\-\.0-9a-zA-Z]+)\.([a-zA-Z]){2,7}$/;
var s = email.value;
if(regex.test(s)){
email.classList.remove('is-invalid');
emailError = true;
$('#emailvalid').hide();
CheckUserEmailID();
}
else{
email.classList.add('is-invalid');
$('#emailvalid').show();
emailError = false;
}
//});
}
//password check
$('#passcheck').hide();
let passwordError = true;
$('#password').keyup(function () {
validatePassword();
});
function validatePassword() {
let passwordValue =
$('#password').val();
if (passwordValue.length == '') {
$('#passcheck').show();
passwordError = false;
return false;
}
if ((passwordValue.length < 3)||
(passwordValue.length > 10)) {
$('#passcheck').show();
$('#passcheck').html("**length of your password must be between 3 and 10");
$('#passcheck').css("color", "red");
passwordError = false;
return false;
} else {
$('#passcheck').hide();
}
}
// Validate mobile number
$('#mobilecheck').hide();
var fullnameError = true;
$('#phone1').keyup(function () {
validateMobile();
});
function validateMobile() {
//console.log("aaa");
var mobileValue = $('#phone1').val();
if (mobileValue.length == '') {
$('#mobilecheck').show();
fullnameError = false;
return false;
}
else if(mobileValue.length < 10) {
$('#mobilecheck').show();
$('#mobilecheck').html("Mobile must be between 10 and 12");
fullnameError = false;
return false;
}
else {
$('#mobilecheck').hide();
}
}
// Validate address
$('#addressCheck').hide();
var fullnameError = true;
$('#address').keyup(function () {
validateAddress();
});
function validateAddress() {
//console.log("aaa");
var mobileValue = $('#address').val();
if (mobileValue.length == '') {
$('#addressCheck').show();
fullnameError = false;
return false;
}
else if(mobileValue.length < 5) {
$('#addressCheck').show();
$('#addressCheck').html("Address should be more than 5");
fullnameError = false;
return false;
}
else {
$('#addressCheck').hide();
}
}
});
function CheckUserEmailID(){
var emailid = $('#emailid').val();
$.ajax({
type: "POST",
url: "ajax.php",
data: 'usernamecheck='+emailid,
//data: formData,
beforeSend: function(){
$('#mydiv').show();
$("#emailmsg").html('');
},
success: function(data){
$('#mydiv').hide();
if(data == 1)
{
$("#emailmsg").html("<div class='col-md-12'><div class='alert alert-success fade in'><a class='close' title='close' aria-label='close' data-dismiss='alert' href='#'>×</a><strong>Done! </strong> UserName Available. </div> </div>");
// $("#emailmsg").fadeTo(2000, 500).slideUp(500, function(){
// $("#emailmsg").slideUp(500);
// });
//$("body").load("home.php").hide().fadeIn(1500).delay(6000);
//window.location = "profile.php";
//$("#branderror").html();
//$("#profile-img").load(location.href + " #profile-img");
//window.location.href = 'thankyou.php';
//$("#content").load("showdata.php");
}
else
{
$("#emailmsg").html("<div class='col-md-12'><div class='alert alert-danger fade in'><a class='close' title='close' aria-label='close' data-dismiss='alert' href='#'>×</a><strong>Error! </strong>Username Not Available. Try another name Please...</div> </div>");
//$("#branderror2").html(data);
//$("#branderror2").animate({scrollTop: 0}, 1000);
//$('#branderror2').animate({scrollTop:$('#branderror2').offset().top}, 'slow');
// $("html, body, .inner-page").animate({
// scrollTop: $(".inner-page").offset().top
// }, 2000);
}
}
});
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</body>
</html>
ajax.php
if(isset($_POST['insertclinicName']))
{
$clinicname = string_sanitize($_POST['insertclinicName']);
$doctorName = string_sanitize($_POST['doctorName']);
$lname = string_sanitize($_POST['lname']);
$phone1 = string_sanitize($_POST['phone1']);
$phone2 = string_sanitize($_POST['phone2']);
$phone3 = string_sanitize($_POST['phone3']);
$emailid = string_sanitize($_POST['emailid']);
$password1 = string_sanitize($_POST['password1']);
$password2 = string_sanitize($_POST['password2']);
$encrypted = encryptedPassword($password1);
$addStaff = string_sanitize($_POST['addStaff']);
$address = string_sanitize($_POST['address']);
$degree = string_sanitize($_POST['degree']);
//$userid = $_SESSION['userid'];
//$updatedatetime = date("Y-m-d H:i:s");
//$display = '1';
global $db_conx;
$sql = "SELECT emailid FROM `clinic_master` WHERE `emailid` = '".$emailid."' AND `display` = '1' ";
$myquery = mysqli_query($db_conx, $sql);
if(mysqli_num_rows($myquery) == 0)
{
//username available
$clinicCheck = $drname = $phone1Check = $emailidCheck = $password1Check = $password2Check = $passwordsameCheck = true;
//clinic name validation
if(strlen($clinicname) < 5 ){
$err_msg[] = "Very short clinicname!";
$clinicCheck = false;
}
//doctorname name validation
if(strlen($doctorName) < 2 ){
$err_msg[] = "Very short DoctorName!";
$drname = false;
}
//mobile number validation
if (!preg_match('/^[0-9]{10}+$/', $phone1)){
$err_msg[] = "Invalid mobile number format!";
$phone1Check = false;
}
//validate email
if (!filter_var($emailid, FILTER_VALIDATE_EMAIL)) {
$err_msg[] = "Invalid email format!";
$emailidCheck = false;
}
//password1 validation
if(strlen($password1) < 5 ){
$err_msg[] = "Very short password1!";
$password1Check = false;
}
//password2 validation
if(strlen($password2) < 5 ){
$err_msg[] = "Very short password2!";
$password2Check = false;
}
//both password same check
if($password1 != $password2){
$err_msg[] = "Both password are not same!";
$passwordsameCheck = false;
}
if($clinicCheck == true && $drname == true && $phone1Check == true && $emailidCheck == true && $password1Check == true && $password2Check == true && $passwordsameCheck == true){
$add_user = addClinicMaster($clinicname,$doctorName,$lname,$phone1,$phone2,$phone3,$emailid,$password1,$addStaff,$address,$degree);
if ($add_user == true) {
echo '1';
}
}else{
foreach ($err_msg as $msg) {
echo $msg;
}
}
}
else
{
echo 'EmailID not available';
}
//$activity ="New user inserted. userid : $id, Name : $fname $mname $lname Username : $uname";
//$pagename ="new_user.php";
//activitylog($activity,$pagename);
}
function.php
function addClinicMaster($clinicname,$doctorName,$lname,$phone1,$phone2,$phone3,$emailid,$password1,$addStaff,$address,$degree)
{
global $db_conx;
$ip_address = $_SERVER['REMOTE_ADDR'];
$updatedatetime = date("Y-m-d H:i:s");
$todaysdate = date('Y-m-d');
$expiredate = date("Y-m-d", strtotime('+30 days'));
$planid = 1;
$encrypted = encryptedPassword($password1);
$sql = "INSERT INTO clinic_master(clinicname, doctorname, doctorlastname, mobilenumber1, mobilenumber2, landline, emailid, password, staffqty, address, created_at, ipaddress, degree, planid, planstartdate, planenddate) VALUES ('".$clinicname."','".$doctorName."','".$lname."', '".$phone1."', '".$phone2."', '".$phone3."', '".$emailid."', '".$encrypted."', '".$addStaff."', '".$address."', '".$updatedatetime."', '".$ip_address."', '".$degree."', '".$planid."','".$todaysdate."', '".$expiredate."' )";
$query = mysqli_query($db_conx, $sql);
if($query == true){
//insert table data
$cid = mysqli_insert_id($db_conx);
//create user for admin
$post_id = 1; // set as admin role
$adminUser = 1;
$sqlUserInsert = "INSERT INTO `users` (cid, fname, lname, mobile1, mobile2, phone, post_id, username, password, createddate, adminUser) VALUES ('".$cid."', '".$doctorName."','".$lname."', '".$phone1."', '".$phone2."', '".$phone3."', '".$post_id."', '".$emailid."', '".$encrypted."', '".$updatedatetime."', '".$adminUser."')";
$query = mysqli_query($db_conx, $sqlUserInsert);
$userid = mysqli_insert_id($db_conx);
//set all rights for admin
for ($i=1; $i <= 5; $i++) {
$sql3 = "INSERT INTO `user_rights` (rid, userid, updatedby, updatedtime) VALUES ('".$i."', '".$userid."', '".$userid."', '".$updatedatetime."') ";
$query = mysqli_query($db_conx, $sql3);
}
//end all rights for admin
//end data
// log
// $activity ="New Clinic inserted. Clinic ID : $cid, UserId : $userid Clinic Name : $clinicname, Doctor = $doctorName $lname Emailid : $emailid Mobile: $phone1 staff:$addStaff address:$address degree:$degree. Set as admin and set all rights. ";
// $pagename ="register.php";
// activitylog($activity,$pagename);
//send email to current user
global $server_address;
$email = $emailid;
$subject = "Welcome to OPD management system";
$html="";
$html.="Hello ".$doctorName." ".$lname.",";
$html.="<br>You are successfully registered your clinic ".$clinicname.".";
$html.="<br>Your login username: ".$emailid;
$html.="<br>Your login password: ".$password1;
$html.="<br>You can login <a href='".$server_address."'> $server_address</a>";
$html.="<br>You are set as ADMIN and all rights. Now you can add staff like doctor, nurse, receptionist, compunder and many more..";
//send_email($email, $subject, $html);
return true;
} else{
return false;
}
}
connect.php
<?php
date_default_timezone_set("Asia/Calcutta");
global $db_conx;
//local setup
$db_server = "localhost";
$db_user = "root";
$db_password = "";
$db_database = "wwwchira_opdms";
$db_conx = mysqli_connect($db_server, $db_user, $db_password, $db_database);
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}
/*
$check_ban_ip_actual = @$_SERVER['REMOTE_ADDR'];
$check_ban_ip = mysqli_query($db_conx, "SELECT ip_address FROM banned_ip WHERE ip_address = '".$check_ban_ip_actual."'");
if(mysqli_num_rows($check_ban_ip)==1){
die();
}*/
$server_address = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
global $server_address;
global $sitename;
$sitename = "My Clinic Name";
define ("SECRETKEY", "DrSecretKey");
?>
No comments:
Post a Comment