<?= message_box('success'); ?>
<?= message_box('error');
$created = can_action_by_label('workplace', 'created');
$edited = can_action_by_label('workplace', 'edited');
?>
<?php if (!empty($created) || !empty($edited)) {
    if (!empty($workplace_info)) {
        $workplace_id = $workplace_info->workplace_id;
    } else {
        $workplace_id = null;
    }
    $selected_employee_items = array();
    if (!empty($workplace_info->user_id)) {
        $employee_info = $this->db
            ->select('tbl_users.user_id, tbl_users.username, tbl_account_details.fullname, tbl_designations.designations')
            ->from('tbl_users')
            ->join('tbl_account_details', 'tbl_account_details.user_id = tbl_users.user_id', 'left')
            ->join('tbl_designations', 'tbl_designations.designations_id = tbl_account_details.designations_id', 'left')
            ->where('tbl_users.user_id', $workplace_info->user_id)
            ->get()->row();
        if (!empty($employee_info)) {
            $label = !empty($employee_info->fullname) ? $employee_info->fullname : $employee_info->username;
            if (!empty($employee_info->designations)) {
                $label .= ' ( ' . $employee_info->designations . ' )';
            }
            $selected_employee_items[] = array(
                'id' => $employee_info->user_id,
                'text' => $label,
            );
        }
    }
?>
    <div class="nav-tabs-custom">
        <!-- Tabs within a box -->
        <ul class="nav nav-tabs">
            <li class="<?= $active == 1 ? 'active' : ''; ?>"><a href="<?= base_url('admin/attendance/workplace') ?>"><?= lang('manage_workplace') ?></a></li>
            <li class="<?= $active == 2 ? 'active' : ''; ?>"><a href="<?= base_url('admin/attendance/new_workplace') ?>"><?= lang('new_workplace') ?></a></li>
        </ul>
        <div class="tab-content bg-white">
            <input type="hidden" name="user_id">
            <div class="tab-pane <?= $active == 2 ? 'active' : ''; ?>" id="create">
                <?php echo form_open(base_url('admin/attendance/save_workplace/' . $workplace_id), array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data', 'data-parsley-validate' => '', 'role' => 'form')); ?>
                <div class="form-group">
                    <label class="col-lg-3 col-md-3 col-sm-4 control-label"><?= lang('name') ?> <span class="text-danger">*</span></label>
                    <div class="col-lg-6 col-md-6 col-sm-7">
                        <input type="text" class="form-control" value="<?php
                                                                        if (!empty($workplace_info)) {
                                                                            echo $workplace_info->location_name;
                                                                        }
                                                                        ?>" name="location_name" required="">
                    </div>

                </div>

                <div class="form-group">
                    <label class="col-lg-3 col-md-3 col-sm-4 control-label"><?= lang('workplace_details') ?> <span class="text-danger">*</span></label>
                    <div class="col-lg-6 col-md-6 col-sm-7">
                        <textarea class="form-control" name="workplace_details" required=""><?php if (!empty($workplace_info)) {  echo $workplace_info->workplace_details;
                                                                                            }
                                                                                            ?></textarea>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3 control-label"><?= lang('workplace') . ' ' . lang('location'); ?> <span class="text-danger">*</span></label>
                    <div class="col-lg-6">
                        <div class="input-group">
                            <input type="text" class="form-control inputText2" value="<?php
                                                                                        if (!empty($workplace_info)) {
                                                                                            echo $workplace_info->workplace_location;
                                                                                        }
                                                                                        ?>" id="searchTextField" name="workplace_location">
                            <div class="input-group-addon" id="get_location">
                                <i title="<?= lang('get_current_location') ?>" style="cursor: pointer;" data-lucide="map-pin"></i>
                            </div>
                        </div>
                    </div>
                </div>

                <input type="hidden" class="form-control" value="<?= set_value('lat', config_item('office_lat')); ?>" name="office_lat" id="lat">
                <input type="hidden" class="form-control" value="<?= set_value('long', config_item('office_long')); ?>" name="office_long" id="long">

                <div class="form-group">
                    <label class="col-lg-3 control-label"><?= lang('allowed_distance') . ' ' . lang('for') . ' ' . lang('clock'); ?>
                        <span class="text-danger">*</span></label>
                    <div class="col-lg-6">
                        <input type="text" class="form-control" value="<?php
                                                                        if (!empty($workplace_info)) {
                                                                            echo $workplace_info->allowed_radius;
                                                                        }
                                                                        ?>" name="allowed_radius" id="dist_from_office">
                    </div>
                </div>


                <!-- End discount Fields -->

                <div class="form-group">
                    <div class="col-sm-6 col-sm-offset-3">
                        <?= form_multi_lookup_group('user_id', lang('employee') . ' ' . lang('name'), $selected_employee_items, false, array('id' => 'teamPositionFilter'), '', array('type' => 'staff', 'min_length' => 0, 'placeholder' => lang('search') . ' ' . lang('employee'))); ?>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg-3 col-md-3 col-sm-4 control-label"></label>
                    <div class="col-lg-5 col-md-5 col-sm-7">
                        <button type="submit" class="btn btn-sm btn-primary"><?= lang('create_workplace') ?></button>
                    </div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </div>

<?php } ?>

