<?php 

session_start();

$msg="";
$msg_cap="";

if(isset($_POST['form_data_insert'])){
	// code for check server side validation
	if(empty($_SESSION['captcha_code']) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){  
		$msg_cap="CAPTCHA DID NOT MATCH";// Captcha verification is incorrect.		
	}else{// Captcha verification is Correct. Final Code Execute here!		
		$msg_cap="";		
	}
}	


	require_once("../admin/conn.php");
	require_once("../bll/f_common.php");
	require_once("../bll/public_common.php");


if(isset($_POST['form_data_insert'])){
	
	$msg_class="error";
	
	if(strlen($_POST['family_code'])!=8 and strlen($_POST['family_code'])!=0){
		$msg = "ফ্যামিলি কোড ভুল। <br>Family code is incorrect.";
	}

	if($_POST['name']=="" || $_POST['father_name']=="" || $_POST['mother_name']=="" || $_POST['dob']=="" || $_POST['sex']=="" || $_POST['marital_status']=="" || $_POST['national_id']=="" || $_POST['mobile_no']=="" || $_POST['address']=="" || $_POST['district']=="" || $_POST['police_station']=="" || $_POST['post_office']=="" || $_POST['post_code']=="" || $_POST['caste_name']=="" || $_POST['rittik_name']=="" || $_POST['profession_name']=="")
		$msg="এক বা একাধিক তথ্যের ঘর খালি রাখা হয়েছে। অনুগ্রহ করে তথ্যের ঘর সঠিকভাবে পূরণ করুন এবং আবার চেষ্টা করুন। <br>One or more field is missed or left blank. Please fill all field properly and try again.";

	/*duplicate mobile off
	if($_POST['mobile_no']!=''){
		$sql = "SELECT * FROM dixit_registration WHERE mobile_no='".$_POST['mobile_no']."'";
		$query = mysql_query($sql);
		if(mysql_num_rows($query)>0)
			$msg = "দীক্ষিত তথ্য (মোবাইল নম্বর) ইতিমধ্যেই বিদ্যমান।<br>Dixit information (Mobile No) already exists for selected.";
	}
	*/
	
	if(strlen($_POST['mobile_no'])!=11){
		$msg = "মোবাইল নম্বর ১১ সংখ্যার হতে হবে। <br>Mobile number must be 11 digit.";
	}
	if(substr($_POST['mobile_no'],0,3) != "013" and substr($_POST['mobile_no'],0,3) != "017" and substr($_POST['mobile_no'],0,3) != "014" and substr($_POST['mobile_no'],0,3) != "019" and substr($_POST['mobile_no'],0,3) != "015" and substr($_POST['mobile_no'],0,3) != "016" and substr($_POST['mobile_no'],0,3) != "018"){
		$msg = "মোবাইল নম্বর সঠিক নয়। <br>Invalid mobile number.";
	}
	
	$str_mobile = "SELECT * FROM dixit_registration WHERE mobile_no = '".$_POST['mobile_no']."'";
	$query_str_mobile=mysql_query($str_mobile);
	if(mysql_num_rows($query_str_mobile)){
		$msg = "Mobile number already registered.";
	}
	

	if($msg=='' and $msg_cap==''){
		unset($_POST['form_data_insert']);
		$_POST['personal_code'] = 'XXXXXXXX';
		$_POST['ip_address'] = get_client_ip();
		$_POST['otp'] = otp();
		$_POST['otp_verified'] = 'N';
		$_POST['entry_date']=date("Y-m-d H:i:s");
		$_POST['last_update']=date("Y-m-d H:i:s");
		$_POST['entry_by']="SELF";

		if(save_data_into_table($_POST,"dixit_registration")){
			$last_id=mysql_insert_id();
			$msg_class="success"; //success, error, warn
			
			$sms_text="Joy Guru. Thank you for registering at Satsang Bangladesh. Your verificaton code is:  ".$_POST['otp'].". Help Line: 01731293502.";
			
			//sms section start
			
			$number="88".$_POST['mobile_no'];
			$sms_response = sms_send($number, $sms_text);
			$sms_response_code = substr($sms_response, strpos($sms_response,':')+1, strpos($sms_response,',')-strpos($sms_response,':')-1);

			$sms_record_sql = "INSERT INTO sms_dispatch_list VALUES ('0', '" . $sms_response_code . "', '" . $sms_text ."', '" . $number . "', '1', '10001', " . sms_char_len($sms_text, mb_detect_encoding($sms_text)). ", '". $_SESSION['user_id'] . "', '" . $_SESSION['user_id'] . "', NOW(), NOW())";

			//echo $sms_record_sql;

			if(mysql_query($sms_record_sql)){
				//echo "SMS successfully saved.";
			}
			else {
				//echo "SMS faided to save.";
			}

			//sms section ends
			$_POST = reset_default_values();
				header("Location: thanks.php");
			}

		else{
			$msg_class="error"; //success, error, warn
			$msg = "Error while inserting dixit information.";
		}
	}
}
elseif(!isset($_REQUEST['eid']))
{
  //default values
  $_POST = reset_default_values();
}

function reset_default_values()
{
  $default_values = array('family_code'=>'', 'name'=>'NAME: 1', 'father_name'=>'FATHERS NAME: 1', 'mother_name'=>'MOTHERS NAME: 1', 'spouse_name'=>'SPOUSE NAME: 1', 'dob'=>'2024-01-01', 'sex'=>'1', 'marital_status'=>'1', 'national_id'=>'NID: 1', 'mobile_no'=>'01717108671', 'email_address'=>'debashis@gmail.com', 'address'=>'TEST ADDRES: 1', 'district'=>'14', 'police_station'=>'128', 'post_office'=>'661', 'post_code'=>'1214', 'caste_name'=>'50', 'rittik_name'=>'1', 'dixit_date'=>'2024-02-02', 'profession_name'=>'1', 'employer_name'=>'JBPLC');
  return $default_values;
}

?>
  <!--A Design by W3layouts
   Author: W3layout
   Author URL: http://w3layouts.com
   License: Creative Commons Attribution 3.0 Unported
   License URL: http://creativecommons.org/licenses/by/3.0/
   -->
<!DOCTYPE html>
<html lang="en">
   
<!-- Mirrored from demo.w3layouts.com/demos_new/template_demo/04-08-2018/summer_camp_form-demo_Free/1603175437/web/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 22 May 2019 12:50:09 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
		<title>সৎসঙ্গ : দিক্ষিত রেজিস্ট্রেশন</title>
		<!-- Meta tags -->
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="keywords" content=""
		 />
		<script>
		 addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); }
		</script>

		<!-- Meta tags -->
		<!-- Calendar -->
		<link rel="stylesheet" href="css/jquery-ui.css" />
		<!-- //Calendar -->
		<!--stylesheets-->
		<link href="css/style.css" rel='stylesheet' type='text/css' media="all">
		<!--//style sheet end here-->
		<!-- Google fonts here-->
		<link href="http://fonts.googleapis.com/css?family=Barlow:300,400,500" rel="stylesheet">
		<link href="http://fonts.googleapis.com/css?family=Josefin+Sans:300,400,600,700" rel="stylesheet">
		<!--//Google fonts here-->
		<link rel="stylesheet" href="css/jquery-ui.css">
		<link rel="stylesheet" href="css/style.css">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
		<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
		<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
		<link rel="stylesheet" href="/resources/demos/style.css">
		<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
		<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
		
		<script>
			$(document).ready(function(){
				$('#district').on('change', function(){
					var districtId = $(this).val();
					if(districtId){
						$.ajax({
							type:'POST',
							url:'ajaxData.php',
							data:'district='+districtId,
							success:function(html){
								$('#police_station').html(html);
								$('#post_office').html('<option value="">Select Police Station First</option>'); 
							}
						}); 
					}else{
						$('#police_station').html('<option value="">Select District First</option>');
						$('#post_office').html('<option value="">Select Police Station First</option>'); 
					}
				});

				$('#police_station').on('change', function(){
					var police_stationID = $(this).val();
					if(police_stationID){
						$.ajax({
							type:'POST',
							url:'ajaxData.php',
							data:'police_station='+police_stationID,
							success:function(html){
								$('#post_office').html(html);
							}
						}); 
					}else{
						$('#post_office').html('<option value="">Select Police Station First</option>'); 
					}
				});
				
				$('#post_code').on('blur',function(){
					var post_codeID = $(this).val();
					if(post_codeID){
						$.ajax({
							type:'POST',
							url:'ajaxDataPS.php',
							data:'post_code='+post_codeID,
							success:function(html){
								$('#police_station').html(html);
							}
						}); 
						$.ajax({
							type:'POST',
							url:'ajaxDataPO.php',
							data:'post_code='+post_codeID,
							success:function(html){
								$('#post_office').html(html);
							}
						});
						$.ajax({
							type:'POST',
							url:'ajaxDataDist.php',
							data:'post_code='+post_codeID,
							success:function(html){
								//window.alert(html);
								//$('#district').val(14);    //AMINUL 1
								//$('#district').val(html);  //AMINUL 2
								//var dist_code = Number(html);
								$('#district').val(Number(html));
								//$("#district").val(html).attr('selected',true);
								//$('#district option[value="14"]').attr('selected',true);
							}
						}); 
					}
				});
			});
			
			function post_code_load()
			{
				var post_code_id=document.getElementById( "post_office" );

				if(post_code_id)
				{
				 //window.alert("sometext");
					$.ajax({
						type: 'post',
						url: 'ajaxData.php',
						data: {
						id:post_code_id.value
						},
							success: function (response) {
							$( '#post_code' ).val(response);
						}
					});
				}
			}
			
			$(function() {
				$( "#datepicker1" ).datepicker({
					changeMonth: true,
					changeYear: true,
					showAnim: 'slideDown',
					duration: 'fast',
					dateFormat: 'yy-mm-dd',
					yearRange: "-100:+0"
				});
			});
			$(function() {
				$( "#datepicker2" ).datepicker({
					changeMonth: true,
					changeYear: true,
					showAnim: 'slideDown',
					duration: 'fast',
					dateFormat: 'yy-mm-dd',
					yearRange: "-100:+0"
				});
			});
			
		</script>
		<script type='text/javascript'>
			function refreshCaptcha(){
				var img = document.images['captchaimg'];
				img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
			}
		</script>
</head>
<link href="css/main.css" rel="stylesheet" media="all">
<body>
      <h1 class="header-w3ls">
         দীক্ষিত রেজিস্ট্রেশন 
      </h1>
	  <!---728x90--->

      <!-- multistep form -->
      <div class="main-bothside">
         <form name="frm_admin" id="frm_admin" method="post" action="<?php echo $current_page_name;if(isset($_REQUEST["eid"]) && strlen($_REQUEST["eid"]) > 0) echo "?eid=".$_REQUEST["eid"];?>" enctype="multipart/form-data" class="fields">
            <div class="main-title">
               <h2>ব্যাক্তিগত তথ্য/ Personal Information</h2>
            </div>
			<!---728x90--->
            <div class="form-group">
				<?php if($msg!=""){ ?>
				<div class="msg <?php echo $msg_class;?>"><?php echo $msg;?></div>
				<?php } ?>
			</div>
            <div class="form-group">
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="যদি ফ্যামিলি কোড জানা না থাকে, তবে ফাঁকা রাখুন" name="family_code" value="<?php echo $_POST['family_code'];?>" onkeyup="this.value = this.value.replace(/[^0-9]/, '')" maxlength="8">
               </div>
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="নাম/ Name *" required="" name="name" value="<?php echo $_POST['name'];?>">
               </div>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="পিতার নাম/ Father's Name *" required="" name="father_name" value="<?php echo $_POST['father_name'];?>">
               </div>
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="মাতার নাম/ Mother's Name *" required="" name="mother_name" value="<?php echo $_POST['mother_name'];?>">
               </div>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="স্বামী বা স্ত্রী নাম/ Spouse Name *" name="spouse_name" value="<?php echo $_POST['spouse_name'];?>">
               </div>
            </div>
            <div class="form-group">
               <div class="form-mid-w3ls">
                  <input id="datepicker1" type="text" placeholder="জন্মতারিখ/ Date of Birth (YYYY-MM-DD)*" required="" name="dob" value="<?php echo $_POST['dob']; ?>" readonly>
               </div>
               <div class="form-mid-w3ls">
              		<?php $sql ="SELECT id, sex FROM gender_list"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="sex" id="sex" class="form-control buttom" required=''>
					  <option value="">লিঙ্গ/ Gender*</option>
					  <?php while($row=mysql_fetch_array($query)){ ?>
					  <option value="<?php echo $row["id"];?>"><?php echo $row["sex"];?></option>
					  <?php }  ?>
					  <script language="JavaScript" type="text/javascript">document.getElementById("sex").value = '<?php echo $_POST['sex'];?>';</script>
					</select>
					<?php }  ?>
               </div>
               <div class="form-mid-w3ls">
              		<?php $sql ="SELECT id, marital_status FROM marital_status_list"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="marital_status" id="marital_status" class="form-control buttom" required=''>
					  <option value="">বৈবাহিক অবস্থা/ Marital Status*</option>
					  <?php while($row=mysql_fetch_array($query)){ ?>
					  <option value="<?php echo $row["id"];?>"><?php echo $row["marital_status"];?></option>
					  <?php }  ?>
					  <script language="JavaScript" type="text/javascript">document.getElementById("marital_status").value = '<?php echo $_POST['marital_status'];?>';</script>
					</select>
					<?php }  ?>
               </div>
            </div>
            <div class="form-group">
               <div class="form-mid-w3ls">
                  <input type="text" class="form-control" placeholder="ন্যাশনাল আইডি নং/ National ID (English)" required="" name="national_id" value="<?php echo $_POST['national_id'];?>" onkeyup="this.value = this.value.replace(/[^0-9]/, '')">
               </div>
            </div>
            <div class="main-title">
               <h2>যোগাযোগের তথ্য/ Contact Information</h2>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="মোবাইল নং/ Mobile No ইংরেজীতে লিখুন (11 digit)*" required="" name="mobile_no" value="<?php echo $_POST['mobile_no'];?>" onkeyup="this.value = this.value.replace(/[^0-9]/, '')" maxlength="11">
               </div>
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="ইমেইল ঠিকানা/ Email Address (English)" name="email_address" value="<?php echo $_POST['email_address'];?>">
               </div>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="ঠিকানা/ Address*" required="" name="address" value="<?php echo $_POST['address'];?>">
               </div>
            </div>
            <div class="form-group">
               <div class="form-mid-w3ls">
			   		<?php $sql ="SELECT id, district_ban FROM district_list ORDER BY district_ban"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="district" id="district" class="form-control buttom" required='' onchange="fetch_select(this.value);">
						  <option value="">জেলা/ District</option>
						  <?php while($row=mysql_fetch_array($query)){ ?>
						  <option value="<?php echo $row["id"];?>"><?php echo $row["district_ban"];?></option>
						  <?php }  ?>
						  <script language="JavaScript" type="text/javascript">document.getElementById("district").value = '<?php echo $_POST['district'];?>';</script>
					</select>
					<?php }  ?>
               </div>
               <div class="form-mid-w3ls">
			   		<select name="police_station" id="police_station" class="form-control buttom" required=''>
			   		<option value="">থানা / Police Station</option>
					<?php
						if(isset($_POST['form_data_insert'])){
						$ps_po_str = "SELECT PO.post_office_ban, PS.police_station_ban, PO.id post_office, PS.id police_station FROM post_office_list PO LEFT JOIN police_station_list PS ON PO.police_station_id = PS.id WHERE PO.post_code = '".$_POST['post_code']."'";
						$query=mysql_query($ps_po_str);
						if(mysql_num_rows($query)>0){
							$row=mysql_fetch_array($query); ?>
								<option value="<?php echo $row["police_station"];?>"><?php echo $row["police_station_ban"];?></option>
						<?php }}
					?>
					<script language="JavaScript" type="text/javascript">document.getElementById("police_station").value = '<?php echo $_POST['police_station'];?>';</script>
            		</select>
               </div>
               <div class="form-mid-w3ls">
			   		<select name="post_office" id="post_office"  class="form-control buttom" required='' onchange="post_code_load();">
			   		<option value="">পোস্ট অফিস/ Post Office</option>
					<?php
						if(isset($_POST['form_data_insert'])){
						if(mysql_num_rows($query)>0){?>
								<option value="<?php echo $row["post_office"];?>"><?php echo $row["post_office_ban"];?></option>
						<?php }}
					?>
					<script language="JavaScript" type="text/javascript">document.getElementById("post_office").value = '<?php echo $_POST['post_office'];?>';</script> 
					</select>
               </div>
            </div>
            <div class="form-group">
               <div class="form-mid-w3ls">
                  <input type="text" name="post_code" id="post_code" required='' class="form-control" placeholder="পোস্ট কোড/ Post Code" value="<?php echo $_POST['post_code'];?>" onchange="dt_ps_po_load();" onkeyup="this.value = this.value.replace(/[^0-9]/, '')"/>
               </div>
            </div>
            <div class="main-title">
               <h2>দীক্ষার তথ্য/ Dixit Information</h2>
            </div>
            <div class="form-group">
               <div class="form-mid-w3ls">
              		<?php $sql ="SELECT id, caste_name FROM caste_list ORDER BY caste_name"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="caste_name" id="caste_name" class="form-control buttom" required=''>
					  <option value="">গোত্র/ Caste*</option>
					  <?php while($row=mysql_fetch_array($query)){ ?>
					  <option value="<?php echo $row["id"];?>"><?php echo $row["caste_name"];?></option>
					  <?php }  ?>
					  <script language="JavaScript" type="text/javascript">document.getElementById("caste_name").value = '<?php echo $_POST['caste_name'];?>';</script>
					</select>
					<?php }  ?>
               </div>
               <div class="form-mid-w3ls">
              		<?php $sql ="SELECT id, concat(name, ' (', r_code, ')') rittik_name FROM rittik_info ORDER BY name"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="rittik_name" id="rittik_name" class="form-control buttom" required=''>
					  <option value="">দিক্ষাগুরুর নাম/ Dixit Guru Name*</option>
					  <?php while($row=mysql_fetch_array($query)){ ?>
					  <option value="<?php echo $row["id"];?>"><?php echo $row["rittik_name"];?></option>
					  <?php }  ?>
					  <script language="JavaScript" type="text/javascript">document.getElementById("rittik_name").value = '<?php echo $_POST['rittik_name'];?>';</script>
					</select>
					<?php }  ?>
               </div>
               <div class="form-mid-w3ls">
                  <input id="datepicker2" type="text" placeholder="দিক্ষা গ্রহণের তারিখ/ Dixit Date (YYYY-MM-DD)*" name="dixit_date" value="<?php echo $_POST['dixit_date']; ?>" readonly>
               </div>
            </div>
            <div class="main-title">
               <h2>পেশাগত তথ্য/ Professional Information</h2>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
              		<?php $sql ="SELECT id, profession_name, profession_name_ban FROM profession_list ORDER BY profession_name"; ?>
					<?php $query=mysql_query($sql); ?>
					<?php if(mysql_num_rows($query)>0) { ?>
					<select name="profession_name" id="profession_name" class="form-control buttom" required=''>
					  <option value="">পেশা/ Profession*</option>
					  <?php while($row=mysql_fetch_array($query)){ ?>
					  <option value="<?php echo $row["id"];?>"><?php echo $row["profession_name_ban"]."/ ".$row["profession_name"];?></option>
					  <?php }  ?>
					  <script language="JavaScript" type="text/javascript">document.getElementById("profession_name").value = '<?php echo $_POST['profession_name'];?>';</script>
					</select>
					<?php }  ?>
               </div>
               <div class="form-grid-w3ls">
                  <input type="text" class="form-control" placeholder="কর্মরত প্রতিষ্ঠানের নাম/ Name of the employer" name="employer_name" value="<?php echo $_POST['employer_name'];?>">
               </div>
            </div>
            <div class="main-title">
               <h2>Captcha</h2>
            </div>
            <div class="form-group">
               <div class="form-grid-w3ls">
					<?php if(isset($msg)){?>
					<?php echo $msg_cap;?>
					<?php } ?>
					<img src="captcha.php" id='captchaimg'>পাশের লেখাটি নিচে লিখুন <input id="captcha_code" name="captcha_code" type="text">
			   </div>
			</div>
            <input type="submit" value="Submit" name="form_data_insert" onclick="return validate();" class="button1">
         </form>
      </div>
	  <!---728x90--->

      <div class="copy">
         <p>©2024 SATSANG BANGALDESH</p>
      </div>
      <!-- js -->
      
      <!-- //Calendar -->
   </body>

<!-- Mirrored from demo.w3layouts.com/demos_new/template_demo/04-08-2018/summer_camp_form-demo_Free/1603175437/web/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 22 May 2019 12:50:16 GMT -->
</html>