<?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/main_sidebar");
?>
	
     <div class="page-wrapper">
       
            <div class="container-fluid">
                <div class="row">
                    <div class="col s12 l12">
                        <div class="card">
                            <div class="card-content">
                                <h5 class="card-title activator">Clinic Regisration</h5>
                 	<form action="<?php echo base_url(); ?>index.php/saveRegistration" class="form-horizontal" id="block-validate" method="POST" enctype="multipart/form-data" >
						<div class="form-body">
							<div class="divider"></div>
							<div class="card-content">
								<h6 class="font-medium">About Employee</h6>
									 <?php
										 
                    foreach ($edit_data as $key => $data) {
					?>
					<input type="hidden" name="clinic_reg_id" value="<?php echo $data['fk_clinic_id']; ?>" >
										
										<div class="row">
									<div class="col s12 m6 l4">
										<div class="input-field">
											<input id="reg_no" name="reg_no" required  type="text"  value="<?php echo $data['reg_no']; ?>">
											<label for="f-name1">Registration No.</label>
										</div>
									</div>
									 
							</div>
								<div class="row">
									<div class="col s12 m6 l4">
										<div class="input-field">
											<input id="fname" name="fname" required value="<?php echo $data['firstName']; ?>" type="text">
											<label for="f-name1">First Name</label>
										</div>
									</div>
									<div class="col s12 m6 l4">
										<div class="input-field">
											<input id="lname"  name="lname" value="<?php echo $data['lastName']; ?>"  type="text">
											<label for="l-name2">Last Name</label>
										</div>
									</div>
									<div class="col s12 m6 l4">
										<div class="input-field">
											<input id="clinic_name" required value="<?php echo $data['clinic_name']; ?>"  name="clinic_name" type="text">
											<label for="clinic_name">Establishment's Name: *	</label>
										</div>
									</div>
								</div>
							</div>
							<div class="divider"></div>
							<div class="card-content">
								<h6 class="font-medium">Contact Info & Bio</h6>
								<div class="row">
									<div class="col s12 l4">
										<div class="input-field">
											<input id="clinic_email" required name="clinic_email" value="<?php echo $data['email']; ?>"  type="text">
											<label for="clinic_email">Email</label>
										</div>
									</div>
									<div class="col s12 l4">
										<div class="input-field">
											<input id="clinic_website" id="clinic_website" value="<?php echo $data['website']; ?>"  type="text" placeholder="http://">
											<label for="website">Website</label>
										</div>
									</div>
									<div class="col s12 l4">
										<div class="input-field">
											<input id="clinic_contact" name="clinic_contact"  value="<?php echo $data['contact_no']; ?>"  maxlength="10" minlength="10" type="text">
											<label for="cnno">Contact Number</label>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col s12 m6 l6">
										<div class="input-field">
											<input type="text" id="clinic_login" required value="<?php echo $data['clinic_username']; ?>"  name="clinic_login">
											<label for="bio">Login Id: *	</label>
											<p> 	(Login ID you enter, lets you sign in to Clinical Establishment Application.)</p>
										</div>
									</div>
									<div class="col s12 m6 l6">
										<div class="input-field">
											<input id="clinic_password"  required name="clinic_password" value="<?php echo $data['clinic_password']; ?>"  type="text">
											<label for="l-name2">Password</label>
										</div>
									</div>
								</div>
								<div class="row">
                                         	<div class="col s12 m6 l6">
										<div class="input-field">
									 
										<select name="package_id" id="package_id">
										<option value="">Select Package Type</option>
										<?php
											for ($i = 0; $i < count($packages_data); ++$i) {
																	?>
											<option <?php if($data['package_id']==$packages_data[$i]->package_id) { echo "selected"; } ?> value="<?php echo $packages_data[$i]->package_id; ?>"><?php echo $packages_data[$i]->package_name; ?></option>
											<?php } ?>	
										
										
										</select>
											<label for="f-name1">Packages</label>
										</div>
									</div>
									
                                         	<div class="col s12 m6 l6">
                                            <div class="input-field col s9">
                                                <div class="file-field input-field">
                                                    <div class="btn cyan">
                                                        <span>ID Proof File</span>
                                                        <input type="file">
                                                    </div>
                                                    <div class="file-path-wrapper">
                                                        <input class="file-path validate" name="clinic_id_proof" id="clinic_id_proof" type="text" placeholder="Choose File Here">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        </div>
							 <div class="row">
									<div class="col s12">
										<div class="input-field">
											<textarea id="short_desc" name="short_desc" class="materialize-textarea"><?php echo $data['clinic_info']; ?></textarea>
											<label for="bio">Short Description</label>
										</div>
									</div>
								</div>
								
										<?php 
										$cnt=0;
										    foreach ($branchdata as $key => $kdata) {
										?>
										<input type="hidden" name="branch_id[]" id="branch_id<?php echo $cnt; ?>" value="<?php echo $kdata['branch_id']; ?>">
								   <div class="row branch_panel">
                                            <div class="col s12 l4">
                                               <div class="input-field">
                                                   
                                                      <input id="branch_name<?php echo $cnt; ?>"  required name="branch_name[]" value="<?php echo $kdata['branch_name']; ?>"  type="text" > <label for="email3">Branch Name :</label>
                                                   
                                                </div>
                                            </div>
                                             <div class="col s12 l4">
                                               <div class="input-field">
                                                   
                                                        <input id="branch_email<?php echo $cnt; ?>"  required name="branch_email[]" value="<?php echo $kdata['branch_email']; ?>"  type="text"><label for="bio1">Email :</label>
                                               
                                              
                                            </div>
											</div>
                                            <div class="col s12 l4">
                                                <div class="input-field">
                                                   <input id="branch_contact<?php echo $cnt; ?>" onkeypress="return isNumber(event);"   maxlength="12" minlength="10" required name="branch_contact[]" value="<?php echo $kdata['branch_contact']; ?>"  type="text"> 
													   <label for="con_no1">Contact No :</label>
                                                    </div> 
                                            </div>
                                         
											 <div class="col s12 m6 l4">
										<div class="input-field">
											<input id="branch_code<?php echo $cnt; ?>"   name="branch_code[]" type="text" value="<?php echo $kdata['branch_code']; ?>" required>
											<label for="l-name2">Branch Code</label>
										</div>
									</div>
								<div class="col s12 m6 l8">
                                                 <div class="input-field">
                                                        
                                                    <input id="branch_address<?php echo $cnt; ?>"  required name="branch_address[]" value="<?php echo $kdata['branch_address']; ?>"  type="text"> 

													<label for="web1">Branch Address : </label>
                                                    </div>
                                            </div>
											</div>
											<?php $cnt++ ; } ?>
												<input type="hidden" class="form-control" name="cnt" id="cnt" value="<?php echo $cnt; ?>" />
												<div id="spec_doc">
												
								</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>
					<?php } ?>
							<div class="divider"></div>
							<div class="card-content">
								<div class="form-action">
									<button class="btn waves-effect waves-light cyan" type="submit" name="update_clinic_btn" value="update_clinic_btn">Save
									</button>
								 
								</div>
							</div>
						</div>
					</form> 
					</div>
                         </div>
                    </div>
                  </div>
           </div>
            <!-- ============================================================== -->
            <!-- Container fluid scss in scafholding.scss -->
            <!-- ============================================================== -->
          </div>
    
<?php
	$this->load->view("admin_includes/footer");
?>				
</div>

<script>
	$(document).ready(function() {
	 
		var k= $('#cnt').val(); 				
	$(".addmore_spec").on('click',function(){		
			var data='<div id="chk'+k+'" class="form-group col-md-12">';
			data +='	<div class="branch_panel">';    
			data +='	<div class="row">';    
			data +='<div class="col s12 m6 l4">';
			data +='<div class="input-field">';
			data +='	<input id="branch_name'+k+'" name="branch_name[]" required  type="text">';
			data +='		<label for="f-name1">Branch Name</label>';
			data +='	</div>';
			data +='</div>'; 
			data +='	<div class="col s12 m6 l4">';
			data +='		<div class="input-field">';
			data +='			<input id="branch_email'+k+'" name="branch_email[]" required  type="email">';
			data +='			<label for="f-name1">Branch Email</label>';
			data +='		</div>';
			data +='	</div>';
			data +='	<div class="col s12 m6 l4">';
			data +='		<div class="input-field">';
			data +='			<input id="branch_contact'+k+'" "  maxlength="12" minlength="10" onkeypress="return isNumber(event);" name="branch_contact[]" type="text">';
			data +='			<label for="l-name2">Branch Contact</label>';
			data +='		</div>';
			data +='	</div>';
			data +=' </div>	<div class="row">	<div class="col s12 m6 l4">';
			data +='		<div class="input-field">';
			data +='			<input id="branch_code'+k+'" "   name="branch_code[]" type="text" required>';
			data +='			<label for="l-name2">Branch Code</label>';
			data +='		</div>';
			data +='	</div>';
			
				data +='<div class="col s12 m6 l8">';
			data +='	<div class="input-field">';
			data +='		<input id="branch_address'+k+'"  name="branch_address[]" type="text">';
			data +='		<label for="l-name2">Branch Address</label>';
			data +='	</div>';
			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></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
                }
            },
            //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_password: {
                    required: "Enter a Password"
                },
				clinic_contact: {
                    required: "Enter a Contact No."
                }
            },
            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>