<?php

echo $this->Html->script('jquery-1.11.2.js');
$menu_modules = unserialize($this->request->session()->read('modules'));
?>
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->

<link rel='stylesheet prefetch' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css'>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>

<!-- Latest compiled JavaScript -->
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->

<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js'></script>
<?php echo $this->Html->script('bootstrap-datetimepicker.min.js'); ?>
<?php echo $this->Html->script('bootstrap-datepicker.js'); ?>
<style>
    .icon-password{
        position: relative;
        display: table;
        border-collapse: separate;
    }
    label.error{
        position: absolute;
    }
</style>
<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-body">
                <div class="row">
                    <div class="col-md-6 col-xs-6 tile">
                        <div class="icon-frame col-md-2" id="light">
                            <i class="fa fa-plus-circle" style="color:white"></i>
                        </div>
                        <h3 class="box-title no-margin" style="line-height: 3;float: left;"><?php echo __('&nbspAdd User'); ?></h3>
                    </div>

                    <div class="col-md-6">



                        <div class="row">

                            <div class="col-md-12 text-right" style="line-height: 5;">
                                <?php
                                if (array_key_exists("add", $module_pages)):
                                    $page_id = $module_pages["index"];
                                    foreach ($user_permission as $permission):
                                        if ($permission['page_id'] == $page_id):
                                            ?>
                                <a href="<?php echo $this->Url->build('/member/index/'); ?>"  class="btn btn-success btn-flat btn-grid">
                                    <i class="fa fa-list"></i>
                                                <?php echo __('LIST'); ?>
                                </a>
                                            <?php
                                            break;
                                        endif;
                                    endforeach;
                                endif;
                                ?>



                            </div>
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<div class="box box-primary">
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-md-12">
<?= $this->Form->create(null, ['id' => 'crmusers_form','enctype'=>'multipart/form-data', '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['name'])){ echo 'has-error';} ?>">
                                    <label class="control-label col-lg-3 required">Username</label>
                                    <div class="col-lg-9">
                                             <?php echo $this->Form->input('user.user_name', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                        <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                    </div>
                                </div>

                                <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                    <label class="control-label col-lg-3 required">Full Name</label>
                                    <div class="col-lg-9">
                                             <?php echo $this->Form->input('user.full_name', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                        <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                    </div>
                                </div>

                                    <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                        <label class="control-label col-lg-3 required">Roll No</label>
                                        <div class="col-lg-9">
                                            <?php echo $this->Form->input('user.roll_no', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                            <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                        </div>
                                    </div>

                                    <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                        <label class="control-label col-lg-3 required">Batch No</label>
                                        <div class="col-lg-9">
                                            <?php echo $this->Form->input('user.batch_no', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                            <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                        </div>
                                    </div>

                                <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                        <label class="control-label col-lg-3 required">Organization</label>
                                        <div class="col-lg-9">
                                            <?php echo $this->Form->input('user.organization', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                            <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                        </div>
                                    </div>
                                <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                            <label class="control-label col-lg-3 required">Designation</label>
                                            <div class="col-lg-9">
                                                <?php echo $this->Form->input('user.designation', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>

                                            </div>
                                        </div>
                               <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                                <label class="control-label col-lg-3 required">Mobile Number</label>
                                                <div class="col-lg-9">
                                                    <?php echo $this->Form->input('user.mobile_number', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                                    <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                                </div>
                                            </div>
                               <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>"
                                <div class="form-group row <?php if(isset($errors['name'])){ echo 'has-error';} ?>">
                                    <label class="control-label col-lg-3 required">Blood Group</label>
                                    <div class="col-lg-9">
                                        <?php echo $this->Form->input('user.blood_group', ['label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                        <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                                    </div>
                                </div>
                               <div class="form-group row">
                                    <label class="control-label col-lg-3 required">Email</label>
                                    <div class="col-lg-9">
                                             <?php echo $this->Form->input('user.email', ['label' =>false, 'class' => 'form-control']); ?>
                                        <span class="help-block error">
                                                   <?php
                                                        if (isset($errors['email']['_empty'])) {
                                                            echo $errors['email']['_empty'];
                                                        }

                                                        if (isset($errors['email']['validemail'])) {
                                                            echo $errors['email']['validemail'];
                                                        }
                                                        ?>
                                        </span>
                                    </div>
                                </div>



                                <div class="form-group row">
                                    <label class="control-label col-lg-3 required">Password</label>
                                    <div class="col-lg-9 icon-password">
                                             <?php echo $this->Form->input('user.password', ['type'=>'password','label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                        <span style="cursor:pointer" class="input-group-addon btn-flat" onclick="showPlainPassword(this,`input[name='user[password]']`)"><i class="fa fa-eye"></i></span>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-lg-3 required">Confirm Password</label>
                                    <div class="col-lg-9 icon-password">
                                             <?php echo $this->Form->input('user.confirm_password', ['type'=>'password','label' =>false,['class' => 'required' ], 'class' => 'form-control', 'required' => false]); ?>
                                        <span style="cursor:pointer" class="input-group-addon btn-flat" onclick="showPlainPassword(this,`input[name='user[confirm_password]']`)"><i class="fa fa-eye"></i></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('/Member/index/'); ?>"  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>
$('#crmusers_form').validate({
    rules:{
        'user[user_name]':'required',
        'user[full_name]':'required',
        'user[last_name]':'required',
        'user[email]':{
		  required: true,
		  email: true,
          maxlength:70
		},
        'user[password]':{
		  required: true,
          minlength: 6
		},
        'user[confirm_password]':{
		  required: true,
                  equalTo: "#user-password",
                  minlength: 6
		},
        'user[title]':'required',
        'controller_id[]':'required',
        'user[status]':'required',
        'user[queue_id]':'required'
    },
    messages: {
    'user[user_name]':{
        required: "Please enter username"
    },
    'user[first_name]':{
        required: "Please enter first name"
    },
    'user[last_name]':{
        required: "Please enter last name"
    },
    'user[email]':{
		  required: "Please enter an email address",
		  email: "Please enter a valid email address"
		},
    'user[password]':{
                 required: "Please enter a password",
                 minlength: "Password length must be greater than six"
    },
    'user[confirm_password]':{
                 required: "Please enter password again",
                 equalTo: "Confirm password doesn't match",
                 minlength: "Password length must be greater than six"
    },
    'user[title]':{
                 required: "Please enter user title"
    },
    'controller_id[]':{
                 required: "Statistics permission must be given"
    },
    'user[status]':{
                 required: "Please select a status"
    },
    'user[queue_id]':{
                 required: "Please select a queue"
    }
  },
  highlight: function(element) {
        $(element).parent().addClass("has-error");
    },
  submitHandler: function(form) {
            form.submit();
        }
});

</script>
<?php echo $this->element('common/employee_as_admin_checkbox_js'); ?>
<?php echo $this->Html->script('client_form');?>