<style>
    h1{font-size:22px;text-align:center;font-weight:700;}
    .form-group-l{width:50%;float:left;padding:10px;}
    .form-group{padding:10px;}
</style>
<?php
$sid=$this->uri->segment('3');
$doc_id=$this->uri->segment('4');
$acedemic_session='';
if($doc_id == ''){
    $acedemic_session=$this->session->userdata('acedemic_session');    
}




$doc_type='Reimbursment Cea Certificate';
$doc_table='reimbursment_cea_certificate';

$sch_no='';
$student_name='';
$gender='';
$father_name='';
$section='';
$roll_no='';
$dob='';

$ac_year_start ='';
$ac_year_end ='';

$doc_copy_order='';
$issuing_date='';
$place='';
$doc_fee='';
$course_id='';

$refrence_number='';
$form_title='';
if($doc_id !=''){
    $form_title='Update Certificate';
    $get_document_data=$this->CertificateModel->get_item_data($doc_id,$doc_table);
    if($get_document_data){
        foreach($get_document_data as $document_data){
            $sch_no=$document_data['sch_no'];
            $student_name=$document_data['student_name'];
            $gender=$document_data['gender'];
            $father_name = $document_data['parent_name'];
            $section=$document_data['sec'];
            $roll_no=$document_data['roll_no'];
            $dob=date('Y-m-d',strtotime($document_data['dob']));
            $ac_year_start=$document_data['ac_year_start'];
            // $ac_year_start=$this->session->userdata('y1');
            $ac_year_end=$document_data['ac_year_end'];
            $acedemic_session=$document_data['acedemic_session'];
            // $ac_year_end= $this->session->userdata('y2');

            $doc_copy_order=$document_data['doc_copy_order'];
            $issuing_date=date('Y-m-d',strtotime($document_data['issuing_date']));
            $place=$document_data['place'];
            $refrence_number=$document_data['ref_no'];
            $course_id=$document_data['course_id'];
            $doc_fee=$document_data['doc_fee'];
        }
    }
}else{
    $form_title='Issue Certificate';
    $student_table='student';
    $get_student_info=$this->CertificateModel->get_item_data($sid,$student_table);
    if($get_student_info){
        foreach($get_student_info as $student_info){
            $sch_no=$student_info['sch_no'];
            $student_name=$student_info['student_name'];
            $gender=$student_info['gender'];
            $father_name=$student_info['father_name'];
            $section=$student_info['section'];
            $roll_no=$student_info['roll_no']; 
            $dob=date('Y-m-d',strtotime($student_info['dob']));
            $ac_year_start = $this->session->userdata('y1');
            $ac_year_end = $this->session->userdata('y2');
        }
    }
}
$doc_count=1;        
if($doc_copy_order !=''){
    $doc_count=$doc_copy_order;
}else{
    
    $get_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
    if($get_docs){
        foreach($get_docs as $docs){
            $doc_count=$doc_count + 1;
        }
    }
}

$active_course_id='';
$get_active_course_info=$this->CertificateModel->student_course_data($sid,$acedemic_session);
if($get_active_course_info){
    foreach($get_active_course_info as $course_info){
        $active_course_id=$course_info['course_id'];
    }
}
?>
<div class="container mt-3 mb-3 pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Certificate/dashboard">Certificate</a></li>
                <li class="breadcrumb-item"><a href="#">Reimbursment Cea Certificate</a></li>
                <li class="breadcrumb-item"><a href="#">Issue Reimbursment Cea Certificate</a></li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Sr. No</th>
                            <th>Student Name</th>
                            <th>Course</th>
                            <th>Date</th>
                            <th>Issued By</th>
                            <th>Copy</th>
                            <th>View</th>
                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $all_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
                        if($all_docs){
                            foreach($all_docs as $docs){
                                $tid=$docs['cat_by'];
                                $staff_table='school_staff';
                                $staff_name='';
                                $staff_info=$this->CertificateModel->get_item_data($tid,$staff_table);
                                if($staff_info){
                                    foreach($staff_info as $staffinfo){
                                        $staff_name=$staffinfo['name'];
                                    }
                                }
                        ?>
                        <tr>
                            <td><?php echo $docs['id'];?></td>
                            <td><?php echo $docs['student_name'];?></td>
                            <td><?php echo $docs['class'];?></td>
                            <td><?php echo date('d-M-Y',strtotime($docs['issuing_date']));?></td>
                            <td><?php echo $staff_name;?></td>
                            <td><?php echo $docs['doc_copy_order'];?></td>
                            <td><a href="<?php echo base_url();?>Certificate/reimbursment_cea_certificate/<?php echo $docs['id'];?>" class="btn btn-sm btn-info" target="_blank">View</a></td>
                            
                        </tr>
                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
            <form method="post" action="#">
                
                <h1 class="main-heading mt-3">Issue Reimbursment Cea Certificate</h1>
                <?php 
                if($success){
                ?>
                <div class="alert alert-success"><?php echo $success;?></div>    
                <?php
                }
                if($error){
                ?>
                <div class="alert alert-danger"><?php echo $error;?></div>
                <?php
                }
                
                ?>
                <hr>
                <input type="hidden" name="doc_id" value="<?php echo $doc_id; ?>">
                <input type="hidden" name="sid" value="<?php echo $sid; ?>">
                <div class="form-group form-group-l">
                    <label>Refrence Number</label>
                    <input type="text" name="refrence_number" class="form-control" value="<?php echo $refrence_number; ?>" placeholder="Refrence Number">
                </div>
                <div class="form-group form-group-l">
                    <label>Scholor Number</label>
                    <input type="number" name="sch_no" value="<?php echo $sch_no; ?>" class="form-control">
                </div>
                
                <div class="form-group form-group-l">
                    <label>Student Name</label>
                    <input type="text" name="student_name" class="form-control" value="<?php echo $student_name; ?>" readonly>
                </div>
                <div class="form-group form-group-l">
                    <label>Gender</label>
                    <select class="form-control" name="gender" required>
                        <option value="">-- select gender --</option>
                        <option value="male" <?php if($gender =="male"){echo "selected";}?>>Male</option>
                        <option value="female" <?php if($gender =="female"){echo "selected";}?>>Female</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Salutation</label>
                    <select class="form-control" name="salutation">
                        <option value="Mr.">Mr.</option>
                    </select>
                    
                </div>
                <div class="form-group form-group-l">
                    <label>Father's Name</label>
                    <input type="text" name="father_name" class="form-control" value="<?php echo $father_name; ?>" readonly>
                </div>
                
                
                <div class="form-group form-group-l">
                    <label>Course</label>
                    <select class="form-control" name="course" required>
                        <?php
                        $courses_table='courses';
                        $all_courses=$this->CertificateModel->get_data($courses_table);
                        if($all_courses){
                            foreach($all_courses as $courses){
                        ?>
                        <option value="<?php echo $courses['course']; ?>" <?php if($active_course_id == $courses['id']){echo "selected";}?>><?php echo $courses['course']; echo " "; echo $courses['subject_stream'];?></option> 
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Section</label>
                    
                    <select class="form-control" name="section">
                        <option value="A" <?php if($section =="A"){ echo "selected"; } ?>>A</option>
                        <option value="B" <?php if($section =="B"){ echo "selected"; } ?>>B</option>
                        <option value="C" <?php if($section =="C"){ echo "selected"; } ?>>C</option>
                        <option value="D" <?php if($section =="D"){ echo "selected"; } ?>>D</option>
                        <option value="E" <?php if($section =="E"){ echo "selected"; } ?>>E</option>
                        <option value="F" <?php if($section =="F"){ echo "selected"; } ?>>F</option>
                        <option value="G" <?php if($section =="G"){ echo "selected"; } ?>>G</option>
                        <option value="H" <?php if($section =="H"){ echo "selected"; } ?>>H</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Roll Number</label>
                    <input type="text" name="roll_no" class="form-control" placeholder="Roll Number" value="<?php echo $roll_no; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>D.O.B. :</label>
                    <input type="date" name="dob" value="<?php echo $dob; ?>" class="form-control" required> 
                </div>
                 
                <!--<div class="form-group">-->
                <!--    <input type="text" name="dob_in_words" class="form-control" value="<?php echo $student_info['dob_in_words'];?>" placeholder="Date of birth in words">-->
                <!--</div>-->
                
                
                <div class="form-group form-group-l">
                    <label>Acedemic Session</label>
                    <select class="form-control" name="acedemic_session" required>
                        <?php
                        $acedemic_session_table='academic_session_details';
                        $all_ac_sessions=$this->CertificateModel->get_data($acedemic_session_table);
                        if($all_ac_sessions){
                            foreach($all_ac_sessions as $ac_sessions){
                        ?>
                        <option value="<?php echo $ac_sessions['id'];?>" <?php if($ac_sessions['id'] == $acedemic_session){echo "selected";}?>><?php echo $ac_sessions['year_long'];?></option>
                        <?php
                            }
                        }
                        ?>
                        
                        
                    </select>
                </div>
                
                
                
                <div class="form-group form-group-l">
                    <label>Acedemic Year Start</label>
                    <input type="text" name="ac_year_start" class="form-control" placeholder="Acedemic Year Start" value="<?php echo $ac_year_start; ?>">
                </div>
                
                <div class="form-group form-group-l">
                    <label>Acedemic Year End</label>
                    <input type="text" name="ac_year_end" class="form-control" placeholder="Acedemic Year End" value="<?php echo $ac_year_end; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>Document Type</label>
                    <select class="form-control" name="doc_type">
                        <option value="Reimbursment Cea Certificate">Reimbursment Cea Certificate</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Document Copy</label>
                    <select class="form-control" name="doc_copy_order">
                        <option value="<?php echo $doc_count;?>"><?php echo $doc_count;?> Copy</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Issuing Date</label>
                    <input type="date" class="form-control" name="issuing_date" value="<?php if($issuing_date !=''){ echo $issuing_date; }else{ echo date('Y-m-d'); } ?>" required>
                </div>     
                
                <div class="form-group form-group-l">
                    <label>School Code</label>
                    <input type="text" value="<?php echo school_code; ?>" class="form-control" name="school_code" readonly>
                </div>
                
                <div class="form-group form-group-l">
                    <label>Pattern</label>
                    <input type="text" value="<?php echo pattern; ?>" class="form-control" name="pattern" readonly>
                </div>
                <div class="form-group form-group-l">
                    <label>Doc. Fee</label>
                    <input type="number" class="form-control" name="doc_fee" value="<?php echo $doc_fee; ?>" placeholder="Doc. Fee" required>
                </div>
                <div class="form-group form-group-l">
                    <label>Place</label>
                    <input type="text" class="form-control" name="place" placeholder="Place" value="<?php echo $place; ?>" required>
                </div>
                
                
                <div class="form-group ">
                    <button type="submit" class="btn btn-sm btn-info" name="issue_reimbursment_cea_certificate"><?php echo $form_title; ?></button>
                </div>      
            </form>
            
        </div>
    </div>
</div>

<?php
//     }
// }
?>