<?php $this->load->view('site/layout'); ?>
<?php $this->load->view('site/navbar'); ?>
<style>
    .address{
        border: 1px solid #CCC;
        padding: 10px;
        padding-top: 20px;
        margin-bottom: 20px;
        border-radius: 10px;
    }
    .remove-btn{
        cursor: pointer;
    }
    .city_select{
        width: 100% !important;
    }
</style>

<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><a href="<?= base_url('user/') ?>"><?php echo $this->lang->line('the-students') ?></a></span>
            </div>
        </div>
    </div>
    <div class="kt-portlet">
        <div class="kt-portlet__head">
            <div class="kt-portlet__head-label">
                <h3 class="kt-portlet__head-title">
                    <?php echo $this->lang->line('the-students') ?>
                </h3>
            </div>
        </div>
        <?php if (isset($msg) || validation_errors() !== ''): ?>
            <div class="alert alert-warning alert-dismissible">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa-warning"></i> Alert!</h4>
                <?= validation_errors(); ?>
                <?= isset($msg) ? $msg : ''; ?>
            </div>
        <?php endif; ?>   
        <!--begin::Form-->
        <?php echo form_open_multipart(base_url('' . $thispage . '/edit/' . $edit['id']), array('id' => 'form')); ?>
        <!-- <form class="kt-form kt-form--label-right"> -->
        <div class="kt-portlet__body">
            <?php
            $fields_arr = array('username' => $this->lang->line('name'),
                'cid_user' => $this->lang->line('civil-no'), 'email' => $this->lang->line('e-mail'), 'password' => $this->lang->line('password'),
                'phone' => $this->lang->line('students') . ' ' . $this->lang->line('mobile'),
                'phone_father' => $this->lang->line('guardian') . ' ' . $this->lang->line('mobile'), 'country' => $this->lang->line('nationality'),
                'city' => $this->lang->line('region'), 'blocks' => $this->lang->line('block'), 'street' => $this->lang->line('street'), 'jadah' => $this->lang->line('jadah'),
                'floor' => $this->lang->line('floor'), 'door_no' => $this->lang->line('door-number'), 'address_link' => $this->lang->line('address-link'), 'title' => $this->lang->line('title'),
                'age' => $this->lang->line('date-of-birth'), 'sex' => $this->lang->line('sex'), 'father_work' => $this->lang->line('father_work'), 'mother_work' => $this->lang->line('mother_work'),
                'social_status' => $this->lang->line('social_status'), 'note' => $this->lang->line('note'),
                'building_num' => $this->lang->line('building_num'),
                'profile' => $this->lang->line('customer-image'), 'imageuser' => $this->lang->line('other_attachments'),
                    //'name' => $this->lang->line('name')
            );
            $fields_arr_keys = array_keys($fields_arr);
//            $half_fields = ceil(count($show_fields) / 2) - 1;
//            $fields_count = 0;
            ?>
            <div class="row">
                <div class="col-md-6">
                    <?php
                    if (in_array($fields_arr_keys[0], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('username') ?> <?= in_array('username', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input type="text" class="form-control" id="exampleInputEmail1" placeholder="<?php echo $this->lang->line('enter') ?> <?php echo $this->lang->line('name') ?> " name="username" autofocus value="<?= set_value('username', $edit['username']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    // if (in_array($fields_arr_keys[24], $show_fields)) {
//                        $fields_count++;
                    ?>
                    <!--                        <div class="form-group row">
                                                <label for="example-text-input" class="col-2 col-form-label"><?php //echo $this->lang->line('name')    ?> <?//= in_array('name', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                <div class="col-10">
                                                    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="<?php //echo $this->lang->line('enter')    ?> <?php //echo $this->lang->line('username')    ?> " name="name"  value="<?//= set_value('name', $edit['name']) ?>">
                                                </div>
                                            </div>-->
                    <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    // }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[1], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-search-input" class="col-2 col-form-label"><?php echo $this->lang->line('civil-no') ?>  <?= in_array('cid_user', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input type="number" class="form-control" id="exampleInputPassword1"  name="cid_user" value="<?= set_value('cid_user', $edit['cid_user']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[2], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"> <?php echo $this->lang->line('e-mail') ?> <?= in_array('email', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input type="text" class="form-control" id="exampleInputPassword1" name="email" value="<?= set_value('email', $edit['email']) ?>" >
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[4], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-url-input" class="col-2 col-form-label"><?php echo $this->lang->line('students') ?> <?php echo $this->lang->line('mobile') ?> <?= in_array('phone', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-4">
                                <?= phone_code_select('countryCode') ?>
                            </div>
                            <div class="col-6">
                                <input type="text" class="form-control" id="exampleInputPassword1"  name="phone"  value="<?= set_value('phone', $edit['phone']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[5], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-tel-input" class="col-2 col-form-label"><?php echo $this->lang->line('guardian') ?> <?php echo $this->lang->line('mobile') ?> <?= in_array('phone_father', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input type="text" class="form-control" id="exampleInputPassword1" name="phone_father" value="<?= set_value('phone_father', $edit['phone_father']) ?>" >
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[6], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-password-input" class="col-2 col-form-label"><?php echo $this->lang->line('nationality') ?>   <?= in_array('country', $req_fields) ? '<i class="text-danger">*</i>' : '' ?>  </label>
                            <div class="col-10">
                                <select name="country" class="form-control select2" data-search="true">
                                    <?php foreach ($nationality as $key => $value) { ?>
                                        <?php if ($this->session->userdata('language') == 'english') { ?><option value="<?php echo $value->english; ?>"<?php
                                            if (($this->input->post() && $this->input->post('country') == $value->english) ||
                                                    (!$this->input->post() && $edit['nationality'] == $value->english)) {
                                                echo 'selected';
                                            }
                                            ?>><?php echo $value->english; ?></option> <?php } else { ?>
                                            <option  value="<?php echo $value->arabic; ?>"<?php
                                            if (($this->input->post() && $this->input->post('country') == $value->arabic) ||
                                                    (!$this->input->post() && $edit['nationality'] == $value->arabic)) {
                                                echo 'selected';
                                            }
                                            ?>><?php echo $value->arabic; ?></option>
                                                     <?php
                                                 }
                                             }
                                             ?>
                                </select>
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>





                    <!--<div class="form-group row">
                      <label for="example-email-input" class="col-2 col-form-label"><?php //echo $this->lang->line('title')                                     ?></label>
                      <div class="col-10">
                        <textarea class="form-control" rows="3" placeholder="<?php //echo $this->lang->line('describe')                                      ?> ..." name="title"><?= $edit['title'] ?></textarea>
                      </div>
                    </div>-->
                    <?php
                    if (in_array($fields_arr_keys[15], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"><?php echo $this->lang->line('date-of-birth') ?> <?= in_array('age', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input type="text" class="form-control datepicker_single"  id="datepicker" placeholder=" <?php echo $this->lang->line('the-recipient') ?>" data-date-format="dd/mm/yyyy"  name="age"  value="<?= set_value('age', $edit['age']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[16], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"><?php echo $this->lang->line('sex') ?> <?= in_array('sex', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">

                                <select name="sex" class="form-control select2_plug" data-search="true">
                                    <option value="male" <?php
                                    if (($this->input->post() && $this->input->post('sex') == 'male') ||
                                            (!$this->input->post() && $edit['sex'] == 'male')) {
                                        echo 'selected';
                                    }
                                    ?>><?php echo $this->lang->line('male'); ?></option>
                                    <option value="female" <?php
                                    if (($this->input->post() && $this->input->post('sex') == 'female') ||
                                            (!$this->input->post() && $edit['sex'] == 'female')) {
                                        echo 'selected';
                                    }
                                    ?>><?php echo $this->lang->line('female'); ?></option>
                                </select>
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>

                    <?php
                    $controller_path = dirname(__DIR__, 3);
                    if (file_exists($controller_path . '/controllers/points')) {
                        if (get_ap('points_module', $this->operator_id)) {
//                            $fields_count++;
                            ?>
                            <div class="form-group row">
                                <label for="example-week-input" class="col-2 col-form-label"><?php echo $this->lang->line('tags') ?></label>
                                <div class="col-10">
                                    <select class='form-control select2' name='student_tags[]' multiple>
                                        <?php
                                        $prev_student_tags = explode(',', $edit['student_tags']);
                                        foreach ($student_tags as $tag) {
                                            $selected = '';
                                            if (($this->input->post() && is_array($this->input->post('student_tags')) && in_array($tag->tag_id, $this->input->post('student_tags'))) ||
                                                    (!$this->input->post() && in_array($tag->tag_id, $prev_student_tags))) {
                                                $selected = 'selected';
                                            }
                                            ?>
                                            <option <?= $selected ?> value='<?= $tag->tag_id ?>'><?= $tag->tag_name ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <?php
//                            if ($fields_count == $half_fields) {
//                                echo '</div><div class="col-md-6">';
//                            }
                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[17], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-week-input" class="col-2 col-form-label"><?php echo $this->lang->line('father_work') ?> <?= in_array('father_work', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input class="form-control" name="father_work" value="<?= set_value('father_work', $edit['father_job']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[18], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-week-input" class="col-2 col-form-label"><?php echo $this->lang->line('mother_work') ?> <?= in_array('mother_work', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input class="form-control" name="mother_work" value="<?= set_value('mother_work', $edit['mother_job']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[19], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-week-input" class="col-2 col-form-label"><?php echo $this->lang->line('social_status') ?> <?= in_array('social_status', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <input class="form-control" name="social_status" value="<?= set_value('social_status', $edit['social_status']) ?>">
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[20], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"><?php echo $this->lang->line('note') ?> <?= in_array('note', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                            <div class="col-10">
                                <textarea class="form-control" rows="3" placeholder="<?php echo $this->lang->line('describe') ?> ..." name="note"><?= set_value('note', $edit['note']) ?></textarea>
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[22], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"><?php echo $this->lang->line('customer-image') ?></label>
                            <div class="col-10">
                                <input type="file" class="form-control"  name="profile" >
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                    <?php
                    if (in_array($fields_arr_keys[3], $show_fields)) {
//                        $fields_count++;
                        ?>
                        <div class="form-group row">
                            <label for="example-email-input" class="col-2 col-form-label"></label>
                            <div class="col-10" style="margin-top: 10px">
                                <a onclick="show_password()" style="cursor: pointer;color: blue"><?= $this->lang->line('change_password') ?> </a>
                            </div>
                        </div>

                        <div class="form-group row" id="new_pass">
                            <label for="example-email-input" class="col-2 col-form-label"> <?php echo $this->lang->line('new_password') ?></label>
                            <div class="col-10">
                                <input type="password" class="form-control form-control-solid" value="" name="new_password" placeholder="<?= $this->lang->line('enter') . ' ' . $this->lang->line('new_password') ?>" />
                            </div>
                        </div>
                        <?php
//                        if ($fields_count == $half_fields) {
//                            echo '</div><div class="col-md-6">';
//                        }
                    }
                    ?>
                </div>

                <div class="col-md-6">
                    <div id="address_container">
                        <input type="hidden" name="address_count" value="<?= $this->input->post() || !count($addresses) ? 1 : count($addresses) ?>" id="address_count" />
                        <?php
                        if (!$this->input->post()) {
                            foreach ($addresses as $address) {
                                ?>
                                <div class="address">
                                    <a class="float-right mb-4 remove-btn"><i class="far fa-times-circle fa-2x text-danger"></i></a>
                                    <?php
                                    if (in_array($fields_arr_keys[7], $show_fields)) {
//                                $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-number-input" class="col-2 col-form-label"><?php echo $this->lang->line('region') ?> <?= in_array('city', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-10">
                                                <select name="city[]" class="form-control select2 city_select" data-search="true">
                                                    <option  value=""><?php echo $this->lang->line('select'); ?>
                                                        <?php
                                                        foreach ($region as $key => $value) {
                                                            $selected = '';
                                                            if ($value->english == $address['region'] || $value->arabic == $address['region']) {
                                                                $selected = 'selected';
                                                            }
                                                            ?>
                                                            <?php if ($lang == 'english') { ?><option <?= $selected ?> value="<?php echo $value->english; ?>"><?php echo $value->english; ?></option> <?php } else { ?>
                                                            <option <?= $selected ?> value="<?php echo $value->arabic; ?>"><?php echo $value->arabic; ?></option>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <?php
                                            if (in_array($fields_arr_keys[8], $show_fields)) {
//                    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-datetime-local-input" class="col-3 col-form-label"><?php echo $this->lang->line('block_address') ?> <?= in_array('blocks', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3"name="blocks[]" value="<?= $address['blocks'] ?>" >
                                                    </div>
                                                </div>
                                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                            }
                                            ?>


                                            <?php
                                            if (in_array($fields_arr_keys[10], $show_fields)) {
//    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-month-input" class="col-3 col-form-label"><?php echo $this->lang->line('jadah') ?> <?= in_array('jadah', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3"  name="jadah[]" value="<?= $address['jadah'] ?>" >
                                                    </div>
                                                </div>
                                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                            }
                                            ?>

                                            <?php
                                            if (in_array($fields_arr_keys[11], $show_fields)) {
//    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-week-input" class="col-3 col-form-label"><?php echo $this->lang->line('floor') ?> <?= in_array('floor', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3" name="floor[]"  value="<?= $address['floor'] ?>">
                                                    </div>
                                                </div>
                                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                            }
                                            ?>
                                        </div>
                                        <div class="col-md-6">
                                            <?php
                                            if (in_array($fields_arr_keys[9], $show_fields)) {
//                    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-date-input" class="col-3 col-form-label"><?php echo $this->lang->line('street') ?> <?= in_array('street', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3"  name="street[]"  value="<?= $address['street'] ?>">
                                                    </div>
                                                </div>
                                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                            }
                                            ?>

                                            <?php
                                            if (in_array($fields_arr_keys[21], $show_fields)) {
//                    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-week-input" class="col-3 col-form-label"><?php echo $this->lang->line('building_num') ?> <?= in_array('building_num', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3" name="building_num[]"  value="<?= $address['building_num'] ?>">
                                                    </div>
                                                </div>
                                                <?php
//    if ($fields_count == $half_fields) {
//        echo '</div><div class="col-md-6">';
//    }
                                            }
                                            ?>

                                            <?php
                                            if (in_array($fields_arr_keys[12], $show_fields)) {
//                    $fields_count++;
                                                ?>
                                                <div class="form-group row">
                                                    <label for="example-time-input" class="col-3 col-form-label"><?php echo $this->lang->line('door-number') ?> <?= in_array('door_no', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                                    <div class="col-9">
                                                        <input class="form-control" rows="3" name="door_no[]" value="<?= $address['door_no'] ?>">
                                                    </div>
                                                </div>
                                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                            }
                                            ?>
                                        </div>
                                    </div>
                                    <?php
                                    if (in_array($fields_arr_keys[13], $show_fields)) {
//    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-color-input" class="col-2 col-form-label"><?php echo $this->lang->line('address-link') ?> <?= in_array('address_link', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-10">
                                                <textarea class="form-control" rows="3" name="address_link[]"><?= $address['address_link'] ?></textarea>
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>
                                </div>
                                <?php
                            }
                        }
                        ?>

                        <div class="address <?= !$this->input->post() && !empty($addresses) ? 'empty_inputs' : '' ?>" style="<?= !$this->input->post() && !empty($addresses) ? 'display:none' : '' ?>">
                            <a class="float-right mb-4 remove-btn" style="display: none"><i class="far fa-times-circle fa-2x text-danger"></i></a>
                            <?php
                            if (in_array($fields_arr_keys[7], $show_fields)) {
//                                $fields_count++;
                                ?>
                                <div class="form-group row">
                                    <label for="example-number-input" class="col-2 col-form-label"><?php echo $this->lang->line('region') ?> <?= in_array('city', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                    <div class="col-10">
                                        <select name="city[]" class="form-control select2 city_select" data-search="true">
                                            <option  value=""><?php echo $this->lang->line('select'); ?>
                                                <?php foreach ($region as $key => $value) { ?>
                                                    <?php if ($lang == 'english') { ?><option <?= isset(set_value('city')[0]) && set_value('city')[0] == $value->english ? 'selected' : '' ?> value="<?php echo $value->english; ?>"><?php echo $value->english; ?></option> <?php } else { ?>
                                                    <option <?= isset(set_value('city')[0]) && set_value('city')[0] == $value->arabic ? 'selected' : '' ?> value="<?php echo $value->arabic; ?>"><?php echo $value->arabic; ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                            }
                            ?>
                            <div class="row">
                                <div class="col-md-6">
                                    <?php
                                    if (in_array($fields_arr_keys[8], $show_fields)) {
//                    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-datetime-local-input" class="col-3 col-form-label"><?php echo $this->lang->line('block_address') ?> <?= in_array('blocks', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3" name="blocks[]" value="<?= isset(set_value('blocks')[0]) ? set_value('blocks')[0] : '' ?>">
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>


                                    <?php
                                    if (in_array($fields_arr_keys[10], $show_fields)) {
//    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-month-input" class="col-3 col-form-label"><?php echo $this->lang->line('jadah') ?> <?= in_array('jadah', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3"  name="jadah[]" value="<?= isset(set_value('jadah')[0]) ? set_value('jadah')[0] : '' ?>">
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>

                                    <?php
                                    if (in_array($fields_arr_keys[11], $show_fields)) {
//    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-week-input" class="col-3 col-form-label"><?php echo $this->lang->line('floor') ?> <?= in_array('floor', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3" name="floor[]" value="<?= isset(set_value('floor')[0]) ? set_value('floor')[0] : '' ?>">
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>
                                </div>
                                <div class="col-md-6">
                                    <?php
                                    if (in_array($fields_arr_keys[9], $show_fields)) {
//                    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-date-input" class="col-3 col-form-label"><?php echo $this->lang->line('street') ?> <?= in_array('street', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3"  name="street[]" value="<?= isset(set_value('street')[0]) ? set_value('street')[0] : '' ?>">
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>

                                    <?php
                                    if (in_array($fields_arr_keys[21], $show_fields)) {
//                    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-week-input" class="col-3 col-form-label"><?php echo $this->lang->line('building_num') ?> <?= in_array('building_num', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3" name="building_num[]" value="<?= isset(set_value('building_num')[0]) ? set_value('building_num')[0] : '' ?>">
                                            </div>
                                        </div>
                                        <?php
//    if ($fields_count == $half_fields) {
//        echo '</div><div class="col-md-6">';
//    }
                                    }
                                    ?>

                                    <?php
                                    if (in_array($fields_arr_keys[12], $show_fields)) {
//                    $fields_count++;
                                        ?>
                                        <div class="form-group row">
                                            <label for="example-time-input" class="col-3 col-form-label"><?php echo $this->lang->line('door-number') ?> <?= in_array('door_no', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                            <div class="col-9">
                                                <input class="form-control" rows="3" name="door_no[]" value="<?= isset(set_value('door_no')[0]) ? set_value('door_no')[0] : '' ?>" >
                                            </div>
                                        </div>
                                        <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                                    }
                                    ?>
                                </div>
                            </div>
                            <?php
                            if (in_array($fields_arr_keys[13], $show_fields)) {
//    $fields_count++;
                                ?>
                                <div class="form-group row">
                                    <label for="example-color-input" class="col-2 col-form-label"><?php echo $this->lang->line('address-link') ?> <?= in_array('address_link', $req_fields) ? '<i class="text-danger">*</i>' : '' ?></label>
                                    <div class="col-10">
                                        <textarea class="form-control" rows="3" name="address_link[]"><?= isset(set_value('address_link')[0]) ? set_value('address_link')[0] : '' ?></textarea>
                                    </div>
                                </div>
                                <?php
//                    if ($fields_count == $half_fields) {
//                        echo '</div><div class="col-md-6">';
//                    }
                            }
                            ?>
                        </div>

                    </div>
                    <div class="text-center">
                        <a class="btn" id="add_address"><i class="fa fa-plus fa-2x text-primary" title="<?= $this->lang->line('add_another_address') ?>"></i></a>
                    </div>
                </div>
            </div>
            <!-- <div class="form-group row">
              <label for="example-email-input" class="col-2 col-form-label"><?php echo $this->lang->line('customer-image') ?></label>
              <div class="col-10">
               <input type="file" class="form-control" id="exampleInputFile" name="imageuser[]" multiple>
              </div>
            </div>  -->
        </div>
        <div class="kt-portlet__foot">
            <div class="kt-form__actions">
                <div class="text-center">
                    <button onClick="submit_form()" class="btn btn-primary" name="submit" value="pl"><?php echo $this->lang->line('modification') ?></button>
                </div>
            </div>
        </div>
        </form>
    </div>

    <?php $this->load->view('site/footer_2'); ?>
    <script src="<?= base_url() ?>public/js/pages/crud/forms/widgets/select2.js"></script>
    <script>
                        $('document').ready(function () {
                            $(".select2").select2();
                            $("#datepicker").datepicker({format: 'yyyy-mm-dd'});

                            $("#add_address").click(function () {
                                $(".city_select").select2('destroy');
                                var html = $(".address:first").clone();
                                var count = parseInt($("#address_count").val());
                                var city = '';
                                html.find("input").val("");
                                html.find("textarea").val("");
                                if (typeof post_inputs !== 'undefined') {
                                    city = post_inputs['city'][count];
                                    html.find("input[name='blocks[]']").val(post_inputs['blocks'][count]);
                                    html.find("input[name='street[]']").val(post_inputs['street'][count]);
                                    html.find("input[name='jadah[]']").val(post_inputs['jadah'][count]);
                                    html.find("input[name='building_num[]']").val(post_inputs['building_num'][count]);
                                    html.find("input[name='floor[]']").val(post_inputs['floor'][count]);
                                    html.find("input[name='door_no[]']").val(post_inputs['door_no'][count]);
                                    html.find("input[name='address_link[]']").text(post_inputs['address_link'][count]);
                                }
                                html.find("select").select2();
                                html.find('.remove-btn').show();
                                $("#address_container").append(html);
                                $("#address_count").val(parseInt($("#address_count").val()) + 1);
                                if (city != '') {
                                    $(".city_select:last").val(city);
                                } else {
                                    $(".city_select:last").val('');
                                }
                                $(".city_select").select2();
                                $('.address:last').show();
                                $('.address:last').removeClass('empty_inputs');
                            });
<?php if ($this->input->post()) { ?>
                                var post_inputs = '<?= json_encode($this->input->post()) ?>';
                                post_inputs = JSON.parse(post_inputs);
    <?php for ($i = 1; $i < $this->input->post('address_count'); $i++) {
        ?>
                                    $("#add_address").click();
        <?php
    }
}
?>
                            $(document).on('click', '.remove-btn', function () {
                                $("#address_count").val(parseInt($("#address_count").val()) - 1);
                                $(this).closest('.address').remove();
                            });
                        });
    </script>

    <script>
        $(function () {
            var phone_code = "<?= set_value('countryCode', $edit['phone_code']) ?>";
            $(".code_input").val(phone_code);
            $(".code_input").select2();
            $("#new_pass").hide();
        });
        function show_password() {
            $("#new_pass").show();
        }
        function submit_form() {
            $(".empty_inputs").remove();
            $("#form").submit();
        }
    </script>