<style>
    h1{font-size:22px;text-align:center;font-weight:700;}
    .form-group-wf{width:50%;padding:10px;float:left;}
</style>
<?php

$page_submit_title='';
$student_name='';
$father_name='';
$sch_no='';
$gender='';
$dob='';
$dob_in_words='';
$previous_school='';
$admission_date='';
$active_course_id='';
$doc_copy_order='';
$sid=$this->uri->segment('3');
$doc_id=$this->uri->segment('4');
$admission_class='';
$school_leaving_date='';

$mother_name="";
$mother_salutation="";

$charcter_info="";
$doc_fee="";

$ac_year_start='';
$ac_year_end='';
// if($doc_id !=''){
//     echo $doc_id;
// }else{
//     echo $sid;
// }
$acedemic_session=$this->session->userdata('acedemic_session');

$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'];
    }
}
$doc_type='Student-Transfer-Certificate';
$doc_table='student_transfer_certificate';

if($doc_id !=''){
    $get_student_doc_info=$this->CertificateModel->get_item_data($doc_id,$doc_table);    
    if($get_student_doc_info){
        foreach($get_student_doc_info as $doc_data){
            $sid=$doc_data['sid'];
            $student_name=$doc_data['student_name'];
            $father_name=$doc_data['father_name'];
            
            $mother_name=$doc_data["mother_name"];
            
            $sch_no=$doc_data['sch_no'];
            $gender=$doc_data['gender'];
            $dob=$doc_data['dob'];
            $dob_in_words=$doc_data['dob_in_words'];
            $previous_school=$doc_data['previous_school'];
            $admission_date=$doc_data['admission_date'];
            $doc_copy_order=$doc_data['doc_copy_order'];
            $school_leaving_date=$doc_data['school_leaving_date'];
            $ac_year_start=$doc_data['ac_year_start'];
            $ac_year_end=$doc_data['ac_year_end'];
            $admission_class=$doc_data['admission_class'];
            $page_submit_title='Update Certificate';
            
            $charcter_info=$doc_data["charcter_info"];
            $doc_fee=$doc_data["fee"];
        }
    }
}else{
    // echo $nn;
    
    $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){
            $student_name=$student_info['student_name'];
            $father_name=$student_info['father_name'];
            
            $mother_name=$student_info["mother_name"];
            
            $sch_no=$student_info['sch_no'];
            $gender=$student_info['gender'];
            $dob=$student_info['dob'];
            $dob_in_words=$student_info['dob_in_words'];
            $previous_school=$student_info['previous_school']; 
            $admission_date= $student_info['admission_date'];
            $admission_class=$student_info['admission_class'];
            $page_submit_title='Issue Certificate';    
        
            
            
        }
    }
    $y1=$this->session->userdata('y1');
    $y2=$this->session->userdata('y2');
    $ac_year_start="APRIL ".$y1;
    $ac_year_end="MARCH ".$y2;
}
?>
<style>
    form{padding:20px;box-shadow:0 0 5px silver;margin-top:30px;margin-bottom:30px;}
</style>
<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            
            <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="#">Transfer Certificate</a></li>
                <li class="breadcrumb-item"><a href="#">Issue Transfer Certificate</a></li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th class="sl_no">Sr. No</th>
                            <th>Date</th>
                            <th>Issued By</th>
                            <th>Copy</th>
                            <th>View</th>
                            <th>Edit</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 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/transfer_certificate/<?php echo $docs['id']; ?>" class="btn btn-sm btn-info" target="_blank">View</a></td>
                            <td><a href="<?php echo base_url();?>Certificate/issue_transfer_certificate/<?php echo $docs['sid'].'/'.$docs['id']; ?>" class="btn btn-sm btn-info" target="_blank">Edit</a></td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
            <form method="post" action="#">
                <h1>Issue Student Transfer 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; ?>">
                
                <div class="form-group w-50">
                    <label>Scholor Number</label>
                    <input type="number" name="sch_no" value="<?php echo $sch_no; ?>" class="form-control">
                </div>
                <div class="form-group w-50">
                    <label>Student Name</label>
                    <input type="hidden" name="sid" value="<?php echo $sid;?>">
                    <input type="text" name="student_name" class="form-control" value="<?php echo $student_name;?>" >
                </div>
                <div class="form-group w-50">
                    <label>Salutation</label>                    
                    <select class="form-control" name="salutation">
                        <option value="Mr.">Mr.</option>
                    </select>
                    
                </div>
                <div class="form-group w-50">
                        
                    <label>Father's Name</label>
                    <input type="text" name="father_name" class="form-control" value="<?php echo $father_name;?>" >
                </div>
                
                <div class="form-group w-50">
                    <label>Salutation</label>                    
                    <select class="form-control" name="mother_name_salutation">
                        <option value="Mrs.">Mrs.</option>
                    </select>
                    
                </div>
                <div class="form-group w-50">
                        
                    <label>Mother's Name</label>
                    <input type="text" name="mother_name" class="form-control" value="<?php echo $mother_name;?>" >
                </div>
                
                <div class="form-group w-50">
                    <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 w-50">
                    <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 w-50">
                    <label>Document Type</label>
                    <select class="form-control" name="doc_type">
                        <option value="Student-Transfer-Certificate">Student Transfer Certificate</option>
                    </select>
                </div>
                <div class="form-group w-50">
                    <label>Document Copy</label>
                    <select class="form-control" name="doc_copy_order">
                        <?php 
                        $get_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
                        $doc_count=1;
                        if($doc_copy_order !=''){
                            $doc_count=$doc_copy_order;
                        }else{
                        if($get_docs){
                            foreach($get_docs as $docs){
                                $doc_count=$doc_count + 1;
                            }
                        }    
                        }
                        
                        ?>
                        <option value="<?php echo $doc_count;?>"><?php echo $doc_count;?> Copy</option>
                    </select>
                </div>
                    
                <div class="form-group w-50">
                    <label>D.O.B. :</label>
                    <input type="date" name="dob" value="<?php echo date('Y-m-d',strtotime($dob));?>" class="form-control" required> 
                </div>
                    
                <div class="form-group w-50">
                    <label>D.O.B In Words</label>
                    <input type="text" name="dob_in_words" class="form-control" value="<?php echo $dob_in_words;?>" placeholder="Date of birth in words">
                </div>
                 
                <div class="form-group w-50">
                    <label>Issuing Date</label>
                    <input type="date" class="form-control" name="issuing_date" value="<?php echo date('Y-m-d');?>" required>
                </div> 
                
                <div class="form-group w-50">
                    <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 w-50">
                    <label>Admission Class</label>
                    <input type="text" class="form-control" name="admission_class" placeholder="Admission Class" value="<?php echo $admission_class; ?>">
                </div>
                
                
                <div class="form-group w-50">
                    <label>Admission Date </label>
                    <input type="date" name="admission_date" class="form-control" value="<?php if($admission_date){ echo date('Y-m-d',strtotime($admission_date)); }?>">
                </div>
                
                <div class="form-group w-50">
                    <label>Previous School</label>
                    <input type="text" name="previous_school" class="form-control" placeholder="Previous School" value="<?php echo $previous_school;?>">
                </div>
                
                <div class="form-group w-50">
                    <label>School Leaving Date</label>
                    <input type="date" name="school_leaving_date" class="form-control" value="<?php if($school_leaving_date){ echo date('Y-m-d',strtotime($school_leaving_date)); } ?>">
                </div>
                
                <div class="form-group w-50">
                    <label>School Affiliation</label>
                    <input type="text" name="school_stream" class="form-control" value="ICSE/ISC" readonly>
                </div>
                
                <div class="form-group w-50">
                    <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 w-50">
                    <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 w-50">
                    <label>Charcter Info</label>
                    <input type="text" name="charcter_info" class="form-control" placeholder="Charcter Info" value="Good" value="<?php echo $charcter_info; ?>">
                </div>
                <div class="form-group w-50">
                    <label>Doc. Fee</label>
                    <input type="number" class="form-control" name="doc_fee" placeholder="Doc. Fee" value="<?php echo $doc_fee; ?>">
                </div>
                <div class="form-group w-50">
                    <label>Promotion</label>
                    <input type="text" value="Granted" class="form-control" name="promotion">
                </div>
                
                <div class="w-100">
                    
                
                    <button type="submit" class="btn btn-sm btn-info" name="issue_transfer_certificate"><?php echo $page_submit_title; ?></button></p>
                </div>
            </form>
            
        </div>
    </div>
</div>
