<?php
/*
 * *************************************************
 * Copyright (C) 2021 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php if ($submit_jawaban->count() > 0) : ?>
    <?php
    $list_jawaban = $submit_jawaban->pluck('nilai', 'pertanyaan_id');
    $list_bobot = $submit_jawaban->pluck('bobot', 'pertanyaan_id');
    $total_bobot = 0;
    ?>
    <div class="row">
        <?php foreach ($pertanyaan as $res1) : ?>
            <div class="col-xs-<?= $res1->kolom ?>">
                <div class="form-group">
                    <label class="control-label"><?= $res1->nama ?></label>
                    <?php if ($res1->tipe == Form_pertanyaan_model::TIPE_TEXT): ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? $list_jawaban[$res1->id] : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_DATE) : ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? date('d-m-Y', strtotime($list_jawaban[$res1->id])) : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_DESCRIPTION) : ?>
                        <br /><?= isset($list_jawaban[$res1->id]) ? nl2br($list_jawaban[$res1->id]) : '-' ?>

                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_NUMERIC) : ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? number_format($list_jawaban[$res1->id], 0, ',', '.') : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_FILE) : ?>
                        <br />
                        <?php if (isset($list_jawaban[$res1->id]) && !empty($list_jawaban[$res1->id])): ?>
                            <a href="<?= base_url('../files/uploads/' . $list_jawaban[$res1->id]) ?>" target="_BLANK">Link Document</a>
                        <?php else : ?>
                            -
                        <?php endif; ?>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_IMAGES) : ?>
                        <br />
                        <?php if (isset($list_jawaban[$res1->id]) && !empty($list_jawaban[$res1->id])): ?>
                            <br />
                            <img src="<?= base_url('../img/uploads/' . $list_jawaban[$res1->id]) ?>" class="img img-responsive img-thumbnail" />
                        <?php else : ?>
                            -
                        <?php endif; ?>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_EMAIL) : ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? number_format($list_jawaban[$res1->id], 0, ',', '.') : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_EXPIRE_DATE) : ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? date('d-m-Y', strtotime($list_jawaban[$res1->id])) : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_BIRTH_DATE) : ?>
                        <div class="form-control" style="height:auto;" disabled="disabled">
                            <?= isset($list_jawaban[$res1->id]) ? date('d-m-Y', strtotime($list_jawaban[$res1->id])) : '-' ?>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_OPTIONS) : ?>
                        <div class="input-group">
                            <div class="form-control" style="height:auto;" disabled="disabled">
                                <?= isset($list_jawaban[$res1->id]) ? $list_jawaban[$res1->id] : '-' ?>
                            </div>
                            <span class="input-group-addon">
                                <?= isset($list_bobot[$res1->id]) ? $list_bobot[$res1->id] : '-' ?>
                            </span>
                        </div>
                        <?php
                        if (isset($list_bobot[$res1->id])) {
                            $total_bobot = $total_bobot + $list_bobot[$res1->id];
                        }
                        ?>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_INLINE_OPTION) : ?>
                        <div class="input-group">
                            <div class="form-control" style="height:auto;" disabled="disabled">
                                <?= isset($list_jawaban[$res1->id]) ? $list_jawaban[$res1->id] : '-' ?>
                            </div>
                            <span class="input-group-addon">
                                <?= isset($list_bobot[$res1->id]) ? $list_bobot[$res1->id] : '-' ?>
                            </span>
                        </div>
                        <?php
                        if (isset($list_bobot[$res1->id])) {
                            $total_bobot = $total_bobot + $list_bobot[$res1->id];
                        }
                        ?>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_CHECKBOX) : ?>
                        <div class="input-group">
                            <div class="form-control" style="height:auto;" disabled="disabled">
                                <?php
                                if (!is_array($list_jawaban[$res1->id])) {
                                    $list_jawaban[$res1->id] = explode(';', $list_jawaban[$res1->id]);
                                }
                                ?>
                                <?php if (is_array($list_jawaban[$res1->id])) : ?>
                                    <?php foreach ($list_jawaban[$res1->id] as $jwb) : ?>
                                        - <?= $jwb ?><br />
                                    <?php endforeach; ?>
                                <?php else : ?>
                                    -
                                <?php endif; ?>

                            </div>
                            <span class="input-group-addon">
                                -
                            </span>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_INLINE_CHECKBOX) : ?>
                        <div class="input-group">
                            <div class="form-control" style="height:auto;" disabled="disabled">
                                <?php
                                if (!is_array($list_jawaban[$res1->id])) {
                                    $list_jawaban[$res1->id] = explode(';', $list_jawaban[$res1->id]);
                                }
                                ?>
                                <?php if (is_array($list_jawaban[$res1->id])) : ?>
                                    <?php foreach ($list_jawaban[$res1->id] as $jwb) : ?>
                                        <?= $jwb ?>
                                    <?php endforeach; ?>
                                <?php else : ?>
                                    -
                                <?php endif; ?>

                            </div>
                            <span class="input-group-addon">
                                -
                            </span>
                        </div>
                    <?php elseif ($res1->tipe == Form_pertanyaan_model::TIPE_PHONE) : ?>
                        <div class="input-group">
                            <span class="input-group-addon">+62</span>
                            <div class="form-control" style="height:auto;" disabled="disabled">
                                <?= isset($list_jawaban[$res1->id]) ? phone($list_jawaban[$res1->id]) : '-' ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
    <br />
    <div class="form-group">
        <div class="input-group">
            <span class="input-group-addon">Total Bobot:</span>
            <div class="form-control text-right"><?= $total_bobot ?></div>
        </div>
    </div>
<?php endif; ?>
