<div class="content-wrapper" style="min-height: 946px;">
    <!-- Content Header (Page header) -->
    <section class="content-header">
	<pre>
	<?php
	
	//print_r($character);
	//print_r($character_x);
	?>
	</pre>
	<style>
	.character {    
	
    -webkit-flex-wrap: nowrap; /* Safari 6.1+ */
    display: inline;  
    flex-wrap: nowrap;}

	.character input{    
	width:30px;
	display:inline;
	}	
	
	.ccon{
	max-width:200px;	
	}
	
	</style>
        <h1>
            <i class="fa fa-map-o"></i> <?php echo $this->lang->line('examinations'); ?> <small><?php echo $this->lang->line('student_fee1'); ?></small>  </h1>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><i class="fa fa-search"></i> <?php echo $this->lang->line('select_criteria'); ?></h3>
                    </div>
                    <form action="<?php echo site_url('admin/mark/create') ?>"  method="post" accept-charset="utf-8" id="schedule-form">
                        <div class="box-body">
                            <?php if ($this->session->flashdata('msg')) { ?>
                                <?php echo $this->session->flashdata('msg') ?>
                            <?php } ?>
                            <div class="row">
                                <input type="hidden" name="save_exam" value="search" >                               
                                <?php echo $this->customlib->getCSRF(); ?>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('exam_name'); ?></label>
                                        <select autofocus="" id="exam_id" name="exam_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                            <?php
                                            foreach ($examlist as $exam) {
                                                ?>
                                                <option value="<?php echo $exam['id'] ?>" <?php
                                                if ($exam_id == $exam['id']) {
                                                    echo "selected =selected";
                                                }
                                                ?>><?php echo $exam['name'] ?></option>
                                                        <?php
                                                        $count++;
                                                    }
                                                    ?>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('exam_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('class'); ?></label>
                                        <select  id="class_id" name="class_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                            <?php
                                            foreach ($classlist as $class) {
                                                ?>
                                                <option value="<?php echo $class['id'] ?>" <?php
                                                if ($class_id == $class['id']) {
                                                    echo "selected =selected";
                                                }
                                                ?>><?php echo $class['class'] ?></option>

                                                <?php
                                                $count++;
                                            }
                                            ?>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('class_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1"><?php echo $this->lang->line('section'); ?></label>
                                        <select  id="section_id" name="section_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('section_id'); ?></span>
                                    </div>
                                </div><!-- /.col -->
                            </div><!-- /.row -->
                        </div><!-- /.box-body -->
                    </form>
                </div>
                <?php
                if (isset($examSchedule)) {
                    ?>


                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-users"></i> <?php echo $this->lang->line('fill_mark'); ?> --</h3>
                        </div>
                        <div class="box-body">
                            <?php
                            if (!empty($examSchedule)) {
                                ?>
                                <form role="form" id=""  class="addmarks-form"  method="post" action="<?php echo site_url('admin/mark/create') ?>">
                                    <?php echo $this->customlib->getCSRF(); ?>
                                    <input type="hidden" name="class_id" value="<?php echo $class_id; ?>">
                                    <input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
                                    <input type="hidden" name="exam_id" value="<?php echo $exam_id; ?>">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th>
                                                        <?php echo $this->lang->line('admission_no'); ?>
                                                    </th>
                                                    <th><?php echo $this->lang->line('roll_no'); ?></th>
                                                    <th>
                                                        <?php echo $this->lang->line('student'); ?>
                                                    </th>
                                                    <th>
                                                        Character/Trait
                                                    </th>													
                                                    <?php
                                                    $s = 0;
                                                    foreach ($examSchedule as $key => $student) {
                                                        if (!empty($student['exam_array'])) {
                                                            if ($s == 0) {
                                                                foreach ($student['exam_array'] as $key => $exam_schedule) {
                                                                    ?>
                                                                    <th>
                                                                        <?php
                                                                        echo $exam_schedule['exam_name'] . " (" . substr($exam_schedule['exam_type'], 0, 2) . ": " . $exam_schedule['passing_marks'] . "/" . $exam_schedule['full_marks'] . ") ";
                                                                        ?>
                                                                    </th>
                                                                    <?php
                                                                }
                                                            }
                                                        } else {
                                                            ?>

                                                            <?php
                                                        }
                                                        $s++;
                                                    }
                                                    ?>

                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $s = 0;
                                                foreach ($examSchedule as $key => $student) {
                                                    ?>
                                                <input type="hidden" name="student[]" value="<?php echo $student['student_id'] ?>">

                                                <?php
                                                if (!empty($student['exam_array'])) {
                                                    if ($s == 0) {
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
                                                            ?>
                                                            <input type="hidden" name="exam_schedule[]" value="<?php echo $exam_schedule['exam_schedule_id'] ?>">
                                                            <?php
                                                        }
                                                    }
                                                } else {
                                                    ?>

                                                    <?php
                                                }
                                                $s++;
                                            }
                                            ?>

                                            <?php foreach ($examSchedule as $key => $student) {
                                                ?>

                                                <tr>
                                                    <td>     <?php echo $student['admission_no'] ?></td>
                                                    <td>     <?php echo $student['roll_no'] ?></td>
                                                    <td>        <?php echo $student['firstname'] . " " . $student['lastname']; ?> </td>
													<td>
													<div class='ccon'>
													<span class="character">  C1: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c1"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c1"; ?>" value="<?php echo $student['character']['c1'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C2: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c2"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c2"; ?>" value="<?php echo $student['character']['c2'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C3: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c3"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c3"; ?>" value="<?php echo $student['character']['c3'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C4: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c4"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c4"; ?>" value="<?php echo $student['character']['c4'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C5: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c5"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c5"; ?>" value="<?php echo $student['character']['c5'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C6: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c6"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c6"; ?>" value="<?php echo $student['character']['c6'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C7: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c7"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c7"; ?>" value="<?php echo $student['character']['c7'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C8: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c8"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c8"; ?>" value="<?php echo $student['character']['c8'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C9: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c9"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c8"; ?>" value="<?php echo $student['character']['c9'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C10: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c10"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c10"; ?>" value="<?php echo $student['character']['c10'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C11: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c11"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c11"; ?>" value="<?php echo $student['character']['c11'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C12: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c12"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c12"; ?>" value="<?php echo $student['character']['c12'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C13: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c13"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c13"; ?>" value="<?php echo $student['character']['c13'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C14: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c14"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c14"; ?>" value="<?php echo $student['character']['c14'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C15: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c15"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c15"; ?>" value="<?php echo $student['character']['c15'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C16: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c16"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c16"; ?>" value="<?php echo $student['character']['c16'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C17: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c17"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c17"; ?>" value="<?php echo $student['character']['c17'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C18: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c18"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c18"; ?>" value="<?php echo $student['character']['c18'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C19: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c19"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c19"; ?>" value="<?php echo $student['character']['c19'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C20: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c20"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c20"; ?>" value="<?php echo $student['character']['c20'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C21: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c21"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c21"; ?>" value="<?php echo $student['character']['c21'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C22: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c22"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c22"; ?>" value="<?php echo $student['character']['c22'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C23: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c23"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c23"; ?>" value="<?php echo $student['character']['c23'] ?>" placeholder="Enter Marks"> </span>
													<span class="character">  C24: <input type="text" name="student_c_<?php echo $student['student_id'] . "_c24"; ?>" class="form-control input-sm" id="c_<?php echo $student['student_id'] . "_c24"; ?>" value="<?php echo $student['character']['c24'] ?>" placeholder="Enter Marks"> </span>
													</div>
						<!--		-->					  
													  <br />
													
													</td>
                                                    <?php
                                                    if (!empty($student['exam_array'])) {
                                                        foreach ($student['exam_array'] as $key => $exam_schedule) {
                                                            ?>
                                                            <td>
                                                                <div class="form-group">
                                                                    <div class="checkbox">
                                                                        <label><input type="checkbox" name="student_absent<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id']; ?>" value="ABS" <?php if ($exam_schedule['attendence'] == "ABS") echo "checked"; ?>>Abs</label>
                                                                    </div>
                                                                    C.A 1 Score: <input type="text" name="student_number<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca1"; ?>" class="form-control input-sm" id="subject_<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca1"; ?>" value="<?php echo $exam_schedule['ca1'] ?>" placeholder="Enter Marks"><br />
                                                                    C.A 2 Score: <input type="text" name="student_number<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca2"; ?>" class="form-control input-sm" id="subject_<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca2"; ?>" value="<?php echo $exam_schedule['ca2'] ?>" placeholder="Enter Marks"><br />
                                                                    C.A 3 Score: <input type="text" name="student_number<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca3"; ?>" class="form-control input-sm" id="subject_<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id'] . "_ca3"; ?>" value="<?php echo $exam_schedule['ca3'] ?>" placeholder="Enter Marks"><br />
                                                                    Exam Score: <input type="text" name="student_number<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id']; ?>" class="form-control input-sm" id="subject_<?php echo $student['student_id'] . "_" . $exam_schedule['exam_schedule_id']; ?>" value="<?php echo $exam_schedule['get_marks'] ?>" placeholder="Enter Marks">                                                                
																</div>
                                                            </td>
                                                            <?php
                                                        }
                                                    }else {
                                                        ?>

                                                        <?php
                                                    }
                                                    ?>

                                                </tr>
                                                <?php
                                            }
                                            ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <button type="submit" class="btn btn-primary pull-right" name="save_exam" value="save_exam"><?php echo $this->lang->line('save'); ?></button>
                                </form>
                                <?php
                            } else {
                                ?>

                                <div class="alert alert-info">
                                    <?php echo $this->lang->line('no_record_found'); ?>
                                </div>


                                <?php
                            }
                            ?>
                        </div><!---./end box-body--->
                    </div>
                </div>            

            </div>   <!-- /.row -->
            <?php
        } else {
            
        }
        ?>

    </section><!-- /.content -->
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('change', '#class_id', function (e) {
            $('#section_id').html("");
            var class_id = $(this).val();
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        div_data += "<option value=" + obj.section_id + ">" + obj.section + "</option>";
                    });

                    $('#section_id').append(div_data);
                }
            });
        });
        $(document).on('change', '#feecategory_id', function (e) {
            $('#feetype_id').html("");
            var feecategory_id = $(this).val();
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "feemaster/getByFeecategory",
                data: {'feecategory_id': feecategory_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        div_data += "<option value=" + obj.id + ">" + obj.type + "</option>";
                    });

                    $('#feetype_id').append(div_data);
                }
            });
        });
    });
    $(document).on('change', '#section_id', function (e) {
        $("form#schedule-form").submit();
    });
</script>
<script src="<?php echo base_url(); ?>backend/custom/jquery.validate.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>backend/custom/bootstrap-datepicker.js"></script>
<script>
    $('.sandbox-container').datepicker({
        autoclose: true,
        format: "dd-mm-yyyy"
    });
    $(function () {
        $('.addmarks-form').validate({

            submitHandler: function (form) {
                form.submit();
            }
        });

        $('input[id^="subject_"]').each(function () {
            $(this).rules('add', {
                required: true,
                messages: {
                    required: "Required"
                }
            });
        });
    });
    var class_id = $('#class_id').val();
    var section_id = '<?php echo set_value('section_id') ?>';
    getSectionByClass(class_id, section_id);
    function getSectionByClass(class_id, section_id) {
        if (class_id != "" && section_id != "") {
            $('#section_id').html("");
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        var sel = "";
                        if (section_id == obj.section_id) {
                            sel = "selected";
                        }
                        div_data += "<option value=" + obj.section_id + " " + sel + ">" + obj.section + "</option>";

                    });

                    $('#section_id').append(div_data);
                }
            });
        }
    }
</script>
