<?php
	defined('BASEPATH') OR exit('No direct script access allowed');
	$this->load->view("admin_includes/head");
	$this->load->view("admin_includes/header");
	$this->load->view("admin_includes/sidebar");
	
	
	
?>

<style>
	.doc_tabCls .doc_tab
	{
	padding-top: 4em;
	padding-bottom: 4em;
	}
	.branch_panel{ 
    background: #eee;
    padding: 1em;
	margin-top: 1em;
	}
</style>

<div class="pcoded-content">
	<div class="pcoded-inner-content">
		<!-- Main-body start -->
		<div class="main-body">
			<div class="page-wrapper">
				
				<div class="page-body">
					<div class="row">
						<div class="col-sm-12"> 
							<div class="card">
								<div class="card-header">
									<h5>Clinic Registration Details</h5>
								</div>
								<div class="card-block"> 
									<form action="<?php echo base_url(); ?>index.php/saveRegistration" class="form-horizontal" id="block-validate" method="POST" enctype="multipart/form-data" > 
										<div class = "panel panel-primary clinic_panel">
											<div class = "panel-heading bg-primary">
												<h6 class = "panel-title">Clinic Details </h6>
											</div>
											
											<div class = "panel-body">    
												<div class="row m-t-30">
													<div class="col-md-6">
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Registration No.  <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="reg_no" class="form-control" onchange="check_if_exists_user('reg');"  name="reg_no" required  type="text">
																<span class="messages"></span>
																
																<span id="msg"></span>
															</div>
														</div>
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Clinic Name  <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="clinic_name" class="form-control" required name="clinic_name" type="text">
																<span class="messages"></span>
															</div>
														</div>
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Clinic Email <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="clinic_email" class="form-control" required name="clinic_email" type="text">
																<span class="messages"></span>
															</div>
														</div> 
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Clinic Contact <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="clinic_contact" onchange="check_if_exists_user('contact');"  class="form-control" required onkeypress="return isNumber(event);" name="clinic_contact" maxlength="10" minlength="10" type="text">
																<span class="messages"></span>
																<span id="contact_nomsg"></span>
																
															</div>
														</div> 
													</div>
													
													<div class="col-md-6">
														
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Contact Person Name  <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="contact_person" class="form-control" required name="contact_person" type="text">
																<span class="messages"></span>
															</div>
														</div>
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Contact Person Email <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="contact_person_email" class="form-control" required name="contact_person_email" type="text">
																<span class="messages"></span>
															</div>
														</div> 
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Contact Person contact <span  class="required"> * </span></label>
															<div class="col-sm-8">
																<input id="contact_person_contact" class="form-control" required onkeypress="return isNumber(event);" name="contact_person_contact" maxlength="10" minlength="10" type="text">
																<span class="messages"></span>
															</div>
														</div> 
														
													</div>
													<div class="col-md-6">
														
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">ID Proof File </label>
															<div class="col-sm-8">
																<input class="file-path validate" name="clinic_id_proof" id="clinic_id_proof" type="file" placeholder="Choose File Here">
																<span class="messages"></span>
															</div>
														</div>
														
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Logo File</label>
															<div class="col-sm-8">
																<input class="file-path validate" name="photo_file" id="photo_file" type="file" placeholder="Choose File Here">
																<span class="messages"></span>
															</div>
														</div>
														<div class="form-group row">
															<label class="col-sm-4 col-form-label">Prescription Template</label>
															<div class="col-sm-8">
															
																<select class="form-control" name="prescTemplate" id="prescTemplate"> 
										<option value="">Select Template</option>
										<?php
											for ($i = 0; $i < count($template_data); $i++) {
																	?>
											<option value="<?php echo $template_data[$i]->templateID; ?>"><?php echo $template_data[$i]->templateName; ?></option>
											<?php } ?>	 
										</select>
																<span class="messages"></span>
															</div>
														</div>
													</div> 
													
													
													
												</div> 
											</div> 
										</div> 
										<div class = "panel panel-primary clinic_panel">
											<div class = "panel-heading bg-primary">
												<h6 class = "panel-title">Patient Do's And Donts Details Details </h6>
											</div>
											
											<div class = "panel-body">    
												<div class="col-md-12">
													<div class="form-group row">
														<label class="col-sm-3 col-form-label">New Patient <span  class="required"> * </span></label>
														<div class="col-sm-8">
															<textarea cols="80" rows="10"  id="newpatient" class="form-control ckeditor" required name="newpatient" ></textarea>
															<span class="messages"></span>
														</div>
													</div> 
													<div class="form-group row">
														<label class="col-sm-3 col-form-label">Existing Patient <span  class="required"> * </span></label>
														<div class="col-sm-8">
															<textarea  id="existingpatient" class="form-control ckeditor " required name="existingpatient"  ></textarea>
															<span class="messages"></span>
														</div>
													</div> 
												</div> 
											</div> 
										</div> 
										
										
										
										<div class = "panel panel-primary clinic_panel">
											<div class = "panel-heading bg-primary">
												<h6 class = "panel-title">Gateway Details </h6>
											</div>
											
											<div class = "panel-body">    
												<div class="col-md-12">
													<div class="form-group row">
														<label class="col-sm-4 col-form-label">Payment Gateway API Key <span  class="required"> * </span></label>
														<div class="col-sm-8">
															<input id="payment_api_key" class="form-control" required name="payment_api_key" type="text">
															<span class="messages"></span>
														</div>
													</div> 
													<div class="form-group row">
														<label class="col-sm-4 col-form-label">Payment Gateway Secret Key <span  class="required"> * </span></label>
														<div class="col-sm-8">
															<input id="payment_secret_key" class="form-control" required  name="payment_secret_key" type="text">
															<span class="messages"></span>
														</div>
														</div> <div class="form-group row">
														<label class="col-sm-4 col-form-label">SMS Gateway Link<span  class="required"> * </span></label>
														<div class="col-sm-8">
															<input id="sms_link" class="form-control" required  name="sms_link"  type="text">
															<span class="messages"></span>
															<span class="error">For Mobile Number use #  and   for message use  * <br></span>
															<span> FOR ex:  http://sms2.iissms.co.in/V2/http-api.php?apikey=YOURAPIKEY&senderid=YOURSENDERID&number=#&message=*&format=json 
															</span>
															
														</div>
														
													</div> 
												</div>
											</div>
										</div>
										<div class = "panel panel-primary clinic_panel">
											<div class = "panel-heading bg-primary">
												<h6 class = "panel-title">Bank Details </h6>
											</div>
											
											<div class = "panel-body">       
												<div class="col-md-12"> 
													<div class="row branch_panel">											
														<div class="col-md-4">
															<label class="col-md-9">Bank Account Name<span  class="required"> * </span></label>								 												
															<input id="bankAcc_name" class="form-control" name="bankAcc_name" required  type="text">													
															
														</div>													
														<div class="col-md-4">
															<label class="col-md-6">Bank Name<span  class="required"> * </span></label>								 												
															<input id="bank_name" class="form-control" name="bank_name" required  type="text">													
															
														</div>											
														<div class="col-md-4">
															<label class="col-md-9">Account Number <span  class="required"> * </span></label> 
															<input id="accno"  required class="form-control" name="accno"   type="text">													
															
														</div>											
														<div class="col-md-4">
															<label class="col-md-6">IFSC Code <span  class="required"> * </span></label> 																			
															<input id="ifcsccode"  class="form-control"   required name="ifcsccode" type="text">													
															
														</div>			 										
														
														<div class="col-md-4">
															<label class="col-md-9">Bank Branch Address <span  class="required"> * </span></label> 
															<textarea id="bankbranch" required  class="form-control" name="bankbranch"  ></textarea>		 						
														</div>	 					
													</div>	
													
												</div>	 
											</div>
											
											
											<div class = "panel panel-primary clinic_panel">
												<div class = "panel-heading bg-primary">
													<h6 class = "panel-title">Branch Details </h6>
												</div>
												
												<div class = "panel-body">       
													<div class="col-md-12" id="spec_doc"> 
														<div class="row branch_panel">											
															<div class="col-md-4">
																<label class="col-md-6">Branch Name<span  class="required"> * </span></label>								 												
																<input id="branch_name0" class="form-control" name="branch_name[]" required  type="text">													
																
															</div>											
															<div class="col-md-4">
																<label class="col-md-6">Branch Email</label>							 																			
																<input id="branch_email0"  class="form-control" name="branch_email[]"   type="email">													
																
															</div>											
															<div class="col-md-4">
																<label class="col-md-6">Branch Contact</label> 																			
																<input id="branch_contact0"  class="form-control" onkeypress="return isNumber(event);"  maxlength="12" minlength="10" name="branch_contact[]" type="text">													
																
															</div>			 										
															<div class="col-md-4">
																<label class="col-md-6">Branch Code<span  class="required"> * </span></label> 										
																<input id="branch_code" class="form-control"   name="branch_code[]" type="text" required> 	 						
															</div>											
															<div class="col-md-4">
																<label class="col-md-6">Branch Address</label> 
																<input id="branch_address0"  class="form-control" name="branch_address[]" type="text">										 											 											
															</div>	
															<div style="padding-top:1em;">											
															<button type="button"  class="btn btn-success btn-sm addmore_spec" ><i class="icon icon-plus"></i>Add More Row</button> </div>										
														</div>	
														
														
													</div>			
													
													
												</div>
												<div class="col-md-12  m-b-20 m-t-20">
													
													<div class="row"> 
														<div class="col-sm-6">
															<button type="submit"  name="add_clinic_btn" value="add_clinic_btn" class="btn btn-primary m-b-0">Submit</button>
														</div>
													</div>
												</div>	
											</form>
										</div> 
										
									</div>
								</div>
							</div>			
							
						</div>
					</div>
				</div> 
			</div>
			<?php
				$this->load->view("admin_includes/footer");
			?>				
		</div>
		
		<script>	
			$(document).ready(function() {		
				
				var k=1; 						
				$(".addmore_spec").on('click',function(){					
					var data='<div id="chk'+k+'" class="row branch_panel">';    			
					data +='<div class="col-md-4">';			
					data +='<label class="col-md-6">Branch Name<span  class="required"> * </span></label>	<input class="form-control" id="branch_name'+k+'" name="branch_name[]" required  type="text">';			
					
					
					data +='</div>'; 			
					data +='<div class="col-md-4">';			
					data +='<label class="col-md-6">Branch Email</label>			<input class="form-control" id="branch_email'+k+'" name="branch_email[]"   type="email">';			 		
					data +='		</div>';		
					data +='<div class="col-md-4">';					
					data +='<label class="col-md-6">Branch Contact</label>			<input class="form-control" id="branch_contact'+k+'" "  maxlength="12" minlength="10" onkeypress="return isNumber(event);" name="branch_contact[]" type="text">';			
					
					data +='		</div>  <div class="col-md-4">';
					data +='<label class="col-md-6">Branch Code<span  class="required"> * </span></label>			<input class="form-control" id="branch_code'+k+'" "   name="branch_code[]" type="text" required>';			 	
					data +='		</div>';			
					
					
					data +='<div class="col-md-4">';			
					data +='<label class="col-md-6">Branch Address</label>';	
					
					data +='<input id="branch_address'+k+'" class="form-control"  name="branch_address[]" type="text">';	
					data +='</div>';			
					data +='<div class="col-md-8">';			
					data +='<button type="button"  class="btn btn-danger btn-sm delete"  id="btn_delete" name="btn_delete" onclick="delete_spec('+k+');"><i class="icon icon-minus"></i> Delete Row</button> </div></div>';			
					data +='</div>';			
					$('#spec_doc').append(data);			
					
					$('#btn_delete').show();			
					k++;					
				});			
				
			});	
		</script>	
		<script>		
			function delete_spec(j)	
			{		
				$('#chk'+j).detach();		
			}		
		</script>	
		<script>	
			$(function() {		
				$("#block-validate").validate({			
					rules: {				
						reg_no: {					
							required: true 					
						},				
						fname: {					
							required: true, 					
						},				
						clinic_name: {					
							required: true 					
						},				
						clinic_email: {					
							required: true,					
							email: true					
						}, 				
						clinic_contact: {					
							required: true,					
							minlength: 10					
						},
						'branch_name[]': {					
							required: true 					
						},				
					},			
					//For custom messages			
					messages: {				
						reg_no: {					
							required: "Enter a Clinic Reg.No."					
						}, 				
						fname: {					
							required: "Enter a First Name"					
						}, 				
						clinic_name: {					
							required: "Enter a Clinic Name"					
						}, 				
						clinic_email: {					
							required: "Enter a Email"					
						}, 				
						
						clinic_contact: {					
							required: "Enter a Contact No."					
						},
						'branch_name[]': {					
							required: "Enter a Branch Name"							
						},
					},			
					errorElement: 'div',			
					errorPlacement: function(error, element) {				
						var placement = $(element).data('error');				
						if (placement) {					
							$(placement).append(error)					
							} else {					
							error.insertAfter(element);					
						}				
					},			
					invalidHandler: function(e, validator) {				
						var errors = validator.numberOfInvalids();				
						if (errors) {					
							$('.error-alert-bar').show();					
						}				
					}			
				});		
			});	
		</script>		
		<script>
			function check_if_exists_user(btnval) {
				if(btnval=='reg')
				{
					var fieldval = $("#reg_no").val();
				}
				else{
					var fieldval = $("#clinic_contact").val();
				}
				$.ajax(
				{
					type:"post",
					url: "<?php echo base_url(); ?>index.php/clinicController/Clinic/filename_exists",
					data:{ fieldval:fieldval,btnval:btnval,pageval:'clinic'},
					success:function(response)
					{
						console.log(response);
						
						if (response !=0) 
						{
							if(btnval=='reg')
							{
								var msg='User is already exists';
								$('#msg').html('<span style="color:#ff0700;">'+msg+"</span>");
								$('#reg_no').val('');
								$('#reg_no').focus();
							}
							else{
								var msg='User Contact is already exists';
								$('#contact_nomsg').html('<span style="color:#ff0700;">'+msg+"</span>");
								$('#clinic_contact').val('');
								$('#clinic_contact').focus();
							}
						}
						else
						{
							
							if(btnval=='reg')
							{
								$('#msg').html("");
							}
							else{
								$('#contact_nomsg').html("");
							}
						} 
						
						
					}
				});
			}
			
		</script>				