<div class="row">
    <div class="col-xs-12 col-md-12">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title"><?= $button;?> Rapor Semester</h3>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                    <i class="fa fa-minus"></i></button>
                    <button type="button" class="btn btn-box-tool" onclick="location.reload()" title="Collapse">
                    <i class="fa fa-refresh"></i></button>
                </div>
            </div>
<style>
  .select2{width:100% !important};
</style>                
            <!-- /.box-header -->
            <div class="box-body">
            <?php if ($formulir->nilai_raporsemester=='Ya'){ ?>    
            <form action="<?php echo $action; ?>" method="post">
                <div class="form-group">
                    <label for="int">Nama Peserta <span style="color:red;">*</span> <?php echo form_error('id_peserta') ?></label>
                    <?php
                    if ($button=="Tambah") { ?>
                    <select type="text" class="select2 form-control" name="mySelect" id="mySelect" placeholder="Peserta" value="" onchange="showSelectedValue()" required/>
                        <option value="">Pilih Nama Peserta</option>
                        <?php foreach ($peserta as $key => $value) { ?>
                            <option value="<?= $value->id_peserta;?>"<?php echo set_select('id_peserta', $value->id_peserta); ?>>
                                <?= $value->nisn;?> | <?= $value->no_pendaftaran;?> | <?= $value->nama_peserta;?>
                            </option>
                        <?php }?>
                    </select>
                    <?php } ?>                                   
                </div>
                <div class="form-group">
                <label for="varchar">Nilai Rapor per semester <span style="color:red;">*</span> 
                    <?php echo form_error('satu[]') ?>
                    <?php echo form_error('dua[]') ?>
                    <?php echo form_error('tiga[]') ?>
                    <?php echo form_error('empat[]') ?>
                    <?php echo form_error('lima[]') ?>
                </label>
                <table class="table table-bordered table-striped" id="mytablexxx" style="width:100%">
                    <thead>
                        <tr>
                            <th style="text-align: center" width="10px">No</th>
                            <th style="text-align: center">Mata Pelajaran</th>
                            <th style="text-align: center">Nilai Semester</th>
                        </tr>                     
                    </thead>
                    <tbody>           
                        <?php 
                        $no = 1;
                        for($i=0; $i < $formulir->jml_mapel; $i++) { ?>
                        <tr>  
                            <td style="text-align: center"><?= $no++ ?></td>
                            <td>
                                <input type="hidden" class="form-control" name="id_peserta[]" id="id_peserta" value="<?php echo set_value('id_peserta['.$i.']'); ?>" />
                                <select type="text" class="form-control" name="mapel[]" id="mapel" value="<?= set_value('mapel[]') ?>" required/>
                                    <option value="">Pilih Mata Pelajaran</option>
                                    <option value="PABP"<?php echo set_select('mapel['.$i.']', 'PABP'); ?>>Pendidikan Agama dan Budi Pekerti</option>
                                    <option value="PP"<?php echo set_select('mapel['.$i.']', 'PP'); ?>>Pendidikan Pancasila</option>
                                    <option value="BIND"<?php echo set_select('mapel['.$i.']', 'BIND'); ?>>Bahasa Indonesia</option>
                                    <option value="MTK"<?php echo set_select('mapel['.$i.']', 'MTK'); ?>>Matematika</option>
                                    <option value="IPA"<?php echo set_select('mapel['.$i.']', 'IPA'); ?>>Ilmu Pengetahuan Alam</option>
                                    <option value="IPS"<?php echo set_select('mapel['.$i.']', 'IPS'); ?>>Ilmu Pengetahuan Sosial</option>
                                    <option value="BING"<?php echo set_select('mapel['.$i.']', 'BING'); ?>>Bahasa Inggris</option>
                                    <option value="PJOK"<?php echo set_select('mapel['.$i.']', 'PJOK'); ?>>Pendidikan Jasmani Olahraga dan Kesehatan</option>
                                    <option value="SENBUD"<?php echo set_select('mapel['.$i.']', 'SENBUD'); ?>>Seni Budaya</option>
                                    <option value="PRAKARYA"<?php echo set_select('mapel['.$i.']', 'PRAKARYA'); ?>>Prakarya</option>
                                    <option value="INFORMATIKA"<?php echo set_select('mapel['.$i.']', 'INFORMATIKA'); ?>>Informatika</option>
                                    <option value="MULOK"<?php echo set_select('mapel['.$i.']', 'MULOK'); ?>>Muatan Lokal</option>
                                </select> 
                            </td>
                            <td>
                            <div class="row">
                                <div class="col-xs-12 col-md-2">   
                                    <input type="text" class="form-control" name="satu[]" id="satu" maxlength="5" value="<?php echo set_value('satu['.$i.']'); ?>" placeholder="Semester 1" required/>
                                </div>
                                <div class="col-xs-12 col-md-2"> 
                                    <input type="text" class="form-control" name="dua[]" id="dua" maxlength="5" value="<?php echo set_value('dua['.$i.']'); ?>" placeholder="Semester 2" required/>
                                </div>
                                <div class="col-xs-12 col-md-2"> 
                                    <input type="text" class="form-control" name="tiga[]" id="tiga" maxlength="5" value="<?php echo set_value('tiga['.$i.']'); ?>" placeholder="Semester 3" required/>
                                </div>
                                <div class="col-xs-12 col-md-3"> 
                                    <input type="text" class="form-control" name="empat[]" id="empat" maxlength="5" value="<?php echo set_value('empat['.$i.']'); ?>" placeholder="Semester 4" required/>
                                </div>
                                <div class="col-xs-12 col-md-3"> 
                                    <input type="text" class="form-control" name="lima[]" id="lima" maxlength="5" value="<?php echo set_value('lima['.$i.']'); ?>" placeholder="Semester 5" required/>
                                </div>
                            </div>
                            </td>        
                        </tr>
                        <?php } ?>
                    </tbody>                              
                </table>
                </div>                          

	            <input type="hidden" name="id_raporsemester" value="<?php echo $id_raporsemester; ?>" /> 
	            <button type="submit" class="<?= $this->config->item('botton')?>"><?php echo $button ?></button> 
	            <a href="<?php echo site_url('raporsemester') ?>" class="btn btn-default btn-flat">Batal</a>
            </form><br>
            <div class="callout callout-info">
                <?php foreach ($pengumuman as $text) { ?>               
                    <?php echo $text->text ?>
                <?php } ?>  
            </div>                 
            <?php } else { ?>
                <div class="callout callout-info">
                    Nilai rapor semester pada formulir belum diaktifkan
                </div> 
            <?php } ?>                
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function Angkasaja(evt) 
    {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
        return true;
    }

    function showSelectedValue() 
    {
        var selectElement = document.getElementById("mySelect");
        var selectedValue = selectElement.options[selectElement.selectedIndex].value;
        var textBoxes = document.getElementsByName("id_peserta[]");
        for (var i = 0; i < textBoxes.length; i++) {
            textBoxes[i].value = selectedValue;
        }        
    }
</script> 