<style>
    input[type=number]::-webkit-inner-spin-button, 
    input[type=number]::-webkit-outer-spin-button { 
        -webkit-appearance: none; 
    }

    input[type=number]{
        -moz-appearance: textfield;
    }
</style>

<?php
$sid=$this->uri->segment('3');
$doc_id=$this->uri->segment('4');
$doc_type='Student-Character-Certificate';
$doc_table='student_character_certificate';
$acedemic_session=$this->session->userdata('acedemic_session');
$student_table='student';


$student_name='';
$father_name='';
$gender='';
$dob='';
$dob_in_words='';
$doc_fee='';
$issuing_date='';
$doc_copy_order='';
$admission_date="";
$page_title='';
$to_date="";
$mother_name = "";
$appeared_in="";
$conduct="";
$status="";
$in_school="";
$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'];
    }
}


if($doc_id !=''){
    $page_title='Update Certificate';
    $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){
            $student_name=$doc_data['student_name'];
            $father_name=$doc_data['father_name'];
            $gender=$doc_data['gender'];
            $dob=$doc_data['dob'];
            $dob_in_words=$doc_data['dob_in_words'];
            $doc_fee=$doc_data['fee'];
            $issuing_date=$doc_data['issuing_date'];
            $doc_copy_order=$doc_data['doc_copy_order'];
            $admission_date=$doc_data["admission_date"];
            // $page_title=$doc_data[''];
            $to_date=$doc_data["to_date"];
            $mother_name = $doc_data["mother_name"];
            
            $appeared_in=$doc_data["appeared_in"];
            $conduct=$doc_data['conduct'];
            $status=$doc_data['status'];
            $in_school=$doc_data['in_school'];
            
        }
    }
}else{
    $page_title='Issue Certificate';
    $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'];
            $gender=$student_info['gender'];
            $dob=date('Y-m-d',strtotime($student_info['dob']));
            $dob_in_words=$student_info['dob_in_words'];
            $mother_name=$student_info['mother_name'];
        }
    }
}


$doc_count=1;
if($doc_copy_order !=''){
    $doc_count=$doc_copy_order;
}else{
    $get_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
    $doc_count=1;
    if($get_docs){
        foreach($get_docs as $docs){
            $doc_count=$doc_count + 1;
        }
    }
}
?>


<style>
    form{box-shadow:0 0 5px silver;padding:20px;}
</style>
<div class="container bg-white mt-3 mb-3">
    <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">Documents</a></li>
                <li class="breadcrumb-item">Issue Student Character Certificate</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>
                            <th>Action</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['course'];?></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/character_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_character_certificate/<?php echo $sid."/".$doc_id; ?>" class="btn btn-sm btn-warning bg-white">Edit</a></td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
            
            <form method="post" action="#" class="mt-3 mb-3">
                <h1 class="main-heading mt-3 text-center">Issue Student Character 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 fgwf">
                    <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 fgwf">
                    <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 fgwf">
                    <label>Salutation</label>
                    <select class="form-control" name="father_salutation">
                        <option value="Mr.">Mr.</option>
                    </select>
                </div>
                <div class="form-group fgwf">
                    <label>Father's Name</label>
                    
                    <input type="text" name="father_name" class="form-control" value="<?php echo $father_name;?>" >
                </div>
                
                <div class="form-group fgwf">
                    <label>Salutation</label>
                    <select class="form-control" name="mother_name_salutation">
                        <option value="Mrs.">Mrs.</option>
                    </select>
                </div>
                <div class="form-group fgwf">
                    <label>Mother's Name</label>
                    
                    <input type="text" name="mother_name" class="form-control" value="<?php echo $mother_name; ?>" >
                </div>
                
                <div class="form-group fgwf">
                    <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 fgwf">
                    <label>Document Type</label>
                    <select class="form-control" name="doc_type">
                        <option value="Student-Character-Certificate">Student Character Certificate</option>
                    </select>
                </div>
                <div class="form-group fgwf">
                    <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 fgwf">
                    <label>Issuing Date</label>
                    <input type="date" class="form-control" name="issuing_date" value="<?php if($issuing_date !=''){ echo date('Y-m-d',strtotime($issuing_date)); }else{ echo date('Y-m-d'); } ?>" required>
                </div> 
                <div class="form-group fgwf">
                    <label>D.O.B. :</label>
                    <input type="date" name="dob" value="<?php echo $dob; ?>" class="form-control" required> 
                </div>
                 
                 <div class="form-group fgwf">
                     <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 fgwf">
                    <label>Admission Date</label>
                    <input type="date" class="form-control" name="admission_date" value="<?php if($admission_date !=''){ echo date('Y-m-d',strtotime($admission_date)); }else{ } ?>" required>
                </div> 
                
                <div class="form-group fgwf">
                    <label>To Date</label>
                    <input type="date" class="form-control" name="to_date" value="<?php if($to_date !=''){ echo date('Y-m-d',strtotime($to_date)); }else{ } ?>" required>
                </div> 
                
                
                <div class="form-group fgwf">
                    <label>Status</label>
                    <select class="form-control" name="exam_status" >
                        <option value="passed" <?php if($status =="passed" ){ echo "selected"; } ?>>Passed</option>
                        <option value="failed" <?php if($status =="failed" ){ echo "selected"; } ?>>Failed</option>
                        <option value="appeared" <?php if($status =="appeared" ){ echo "selected"; } ?>>Appeared</option>
                    </select>
                </div>
                
                <div class="form-group fgwf">
                    <label>Appeared In</label>
                    <input type="text" name="appeared_in" class="form-control" placeholder="Appeared In" value="<?php if($appeared_in !=""){ echo $appeared_in; } ?>">
                </div>    
                
                <div class="form-group fgwf">
                    <label>Examination Year</label>
                    <select class="form-control" name="examination_year" 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['y2'];?>" <?php if($ac_sessions['id'] == $acedemic_session){echo "selected";}?>><?php echo $ac_sessions['y2'];?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group fgwf">
                    <label>Doc. Fee</label>
                    <input type="number" class="form-control" name="doc_fee" placeholder="Doc. Fee" value="<?php echo $doc_fee; ?>" required>
                </div>
                <div class="form-group fgwf">
                    <label>Conduct</label>
                    <input type="text" name="conduct" class="form-control" placeholder="Conduct" value="<?php if($conduct !=""){ echo $conduct; }?>">
                </div>
                <div class="form-group fgwf">
                    <label>In School</label>
                    <select class="form-control" name="in_school">
                        <option value="yes" <?php if($in_school == "yes"){ echo "selected"; }?>>Yes</option>
                        <option value="no" <?php if($in_school == "no"){ echo "selected"; }?>>No</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-sm btn-info" name="issue_student_character_certificate"><?php echo $page_title; ?></button>
                    
                </div>        
            </form>
            
        </div>
    </div>
</div>