
<?= $this->element('page_top', array('title' => __('Add'), 'permissions' => $user_permission)); ?>

<div class="box box-primary">
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-md-12">
                <?= $this->Form->create(null, ['id' => 'agent_form', 'class' => 'input-form-section']); ?>

                <div id="basic_info_div">

                    <div class="col-md-9 col-sm-9 col-xs-9 text-left">

                        <div class="form-group row <?php if (isset($errors['first_name'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">First Name</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('first_name', ['label' => false, ['class' => 'required'], 'placeholder' => 'First Name', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['first_name']['_empty'])) {
                                                            echo $errors['first_name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['last_name'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Last Name</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('last_name', ['label' => false, ['class' => 'required'], 'placeholder' => 'Last Name', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['last_name']['_empty'])) {
                                                            echo $errors['last_name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['email'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Email</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('email', ['label' => false, ['class' => 'required'], 'placeholder' => 'Email', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['email']['_empty'])) {
                                                            echo $errors['email']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['phone_number'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Phone Number</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('phone_number', ['label' => false, ['class' => 'required'], 'placeholder' => 'Phone Number', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['phone_number']['_empty'])) {
                                                            echo $errors['phone_number']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['agency_name'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Agency Name</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('agency_name', ['label' => false, ['class' => 'required'], 'placeholder' => 'Agency Name', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['agency_name']['_empty'])) {
                                                            echo $errors['agency_name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['hire_date'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Hire Date</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('hire_date', ['label' => false, ['class' => 'required'], 'placeholder' => 'Hire Date(YYYY-MM-DD)', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['hire_date']['_empty'])) {
                                                            echo $errors['hire_date']['_empty'];
                                                        }
                                                        ?>
                                    </span>

                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['address'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Address</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('address', ['label' => false, ['class' => 'required'], 'placeholder' => 'Address', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['address']['_empty'])) {
                                                            echo $errors['address']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['country_name'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Country</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->control('country_name', ['label' => false, ['class' => 'required'], 'type' => 'select', 'options' => COUNTRIES, 'empty' => 'Select One', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['country_name']['_empty'])) {
                                                            echo $errors['country_name']['_empty'];
                                                        }
                                                        ?>
                                    </span>

                            </div>
                        </div>

                        <div class="form-group row ">
                            <label class="control-label col-lg-3"></label>
                            <div class="col-lg-9">
                                <?= $this->Form->button(__('Submit'), ['class' => 'btn btn-success tab3Save pull-left btn-grid btn-flat', 'id' => 'submit']) ?>
                                <a href="<?php echo $this->Url->build('/agent'); ?>"
                                   class="btn btn-default tab3Save pull-left btn-grid btn-flat btn-orange-color"
                                   id="default-btn">
                                    <?php echo __('Back'); ?>
                                </a>
                            </div>
                        </div>

                    </div>

                    <!-- /.form-group -->
                </div>
                <?= $this->Form->end() ?>
                <!-- /.form-group -->


            </div>
            <!-- /.row -->
        </div>
        <!-- /.box-body -->

    </div>
</div>

<script type="application/javascript">

    $(document).ready(function () {
        $('input[name="hire_date"]').datepicker({autoclose: true, todayHighlight: true, format: 'yyyy-mm-dd'});
    });

    $('#agent_form').validate({
        rules: {
            'first_name': 'required',
            'last_name': 'required',
            'hire_date': 'required',
            'email': 'required',
            'phone_number': 'required',
            'address': 'required',
            'country_name': 'required',
            'agency_name': 'required'

        },
        messages: {

            'first_name': {
                required: "Please enter first name"
            },
            'last_name': {
                required: "Please enter last name"
            }, 'hire_date': {
                required: "Please select hire date"
            },
            'email': {
                required: "Please enter email"
            }, 'phone_number': {
                required: "Please enter phone number"
            }, 'address': {
                required: "Please enter address"
            },
            'country_name': {
                required: "Please select country"
            },
            'agency_name': {
                required: "Please enter passing institution"
            },

        },
        highlight: function (element) {
            $(element).parent().addClass("has-error");
        },
        submitHandler: function (form) {
            form.submit();
        }
    });

</script>

