<?php
$menu_modules = unserialize($this->request->session()->read('modules'));
?>


 <?php 
    $disabled = "disabled"; 
    $required_hide = "required-hide"; 
    if($personalize->is_smtp == 1){
        $disabled = "";
        $required_hide = "";
    } 
 ?>
<style>
    .required-hide{
        display:none;
    }
    #light{
        background-color: #3c8dbc;
        height: 50px;
        width: 55px;
        border-radius: 10px;
        font-size: 22px;
        box-sizing: border-box;
        padding-top: 10px;
        margin-top: 9px;
    }
    .s-btn{
        margin: 10px 10px 20px 0px;
    }
    #default-btn{
        margin: 10px 0px 20px 5px;

    }
    .required{
        color: red;
    }
    .ui-widget-header {
        border: 1px solid #b52626;
        background: #3c8dbc;
        font-weight: bold;
    }
</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="padding-top: 20px; float: left; text-align: left;"><?php echo __('&nbspPersonalize Your Account'); ?></h3>
                    </div>

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



                        <div class="row">
                            <div class="col-md-2 col-xs-6 col-md-offset-10">
                                 <?php echo $this->element('watch_now',['section_name'=>'Personalize Your Account']); ?>
                            </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, ['type'=>'file','id' => 'project_form']); ?>            

                <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['is_smtp'])){ echo 'has-error';} ?>">
                            <div class="col-lg-8">
                                <div class="checkbox">
                                        <label>
                                            <input type="checkbox" <?php echo $personalize->is_smtp == 1 ? 'checked':''; ?> name="is_smtp" value="1">
                                            Use my SMTP to send out Email
                                        </label>
                                    </div>
                            </div>
                            <div class="col-lg-4">
                                <?php if(!empty($personalize)): ?>
                                <?= $this->Html->link(__('Reset to the Default account'), ['action' => 'deletePersonalize', $client->client->id], ['confirm' => __('You are about to reset your login details and account to the default login are you sure you want to do that?'),'escape'=>false]) ?>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['smtp_host'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">SMTP Host<span class="required <?php echo $required_hide;?>"> *</span></label>
                            <div class="col-lg-9">
                                            <?php echo $this->Form->input('smtp_host', ['label' =>false,'value'=>isset($personalize->smtp_host) ? $personalize->smtp_host:'', 'class' => 'form-control has-required', 'placeholder' => _('e.g, smtp.gmail.com'),$disabled]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['smtp_host']['_empty'])) {
                                                            echo $errors['smtp_host']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['username'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Username<span class="required <?php echo $required_hide;?>"> *</span></label>
                            <div class="col-lg-9">
                                            <?php echo $this->Form->input('username', ['label' =>false,'value'=>isset($personalize->username) ? $personalize->username:'', 'class' => 'form-control has-required', 'placeholder' => _('e.g, username@gmail.com'),$disabled]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['username']['_empty'])) {
                                                            echo $errors['username']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['rate_per_hour'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Password<span class="required <?php echo $required_hide;?>"> *</span></label>
                            <div class="col-lg-9">
                                            <?php echo $this->Form->input('password', ['type'=>'password','value'=>isset($personalize->password) ? $personalize->password:'','label' =>false, 'class' => 'form-control has-required','placeholder' => _('Your password'),$disabled]); ?>
                                <span class="help-block">
                                            <?php 
                                            if(isset($errors['password']['_empty'])){ 
                                                echo $errors['password']['_empty'];
                                            }else if (isset ($errors['password']['integer'])) {
                                                    echo $errors['password']['integer'];
                                                }
                                            ?>
                                </span>
                            </div>
                        </div>
                        
                        <div class="form-group row <?php if(isset($errors['smtp_port'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">SMTP Port<span class="required <?php echo $required_hide;?>"> *</span></label>
                            <div class="col-lg-9">
                                             <?php echo $this->Form->input('smtp_port', ['label' =>false,'value'=>isset($personalize->smtp_port) ? $personalize->smtp_port:'', 'class' => 'form-control has-required', 'placeholder' => _('e.g, 587'),$disabled]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['smtp_port']['_empty'])) {
                                                            echo $errors['smtp_port']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['smtp_from'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">SMTP From<span class="required <?php echo $required_hide;?>"> *</span></label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('smtp_from', ['label' =>false,'value'=>isset($personalize->smtp_from) ? $personalize->smtp_from:'', 'class' => 'form-control has-required', 'placeholder' => __('e.g, from@example.com'),$disabled]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['smtp_from']['_empty'])) {
                                                            echo $errors['smtp_from']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <hr/>
                        <div class="form-group row <?php if(isset($errors['email_signature'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Email Signature</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->textarea('email_signature', ['rows'=>2,'label' =>false,'value'=>isset($personalize->email_signature) ? $personalize->email_signature:'', 'class' => 'form-control', 'placeholder' => __('e.g, My Team')]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['smtp_from']['_empty'])) {
                                                            echo $errors['smtp_from']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['domain'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Domain</label>
                            <div class="col-lg-2">
                                <?php echo $this->Form->select('domain_type',['https://'=>'https://','http://'=>'http://'],['label' =>false,'default'=>$personalize->domain_type, 'class' => 'form-control','disabled'=>true]); ?>
                            </div>
                            <div class="col-lg-2">
                                <?php echo $this->Form->input('www', ['label' =>false,'value'=>'www.', 'class' => 'form-control text-center','disabled'=>true]); ?>
                            </div>
                            <div class="col-lg-5">
                                <?php echo $this->Form->input('domain', ['label' =>false,'value'=>isset($personalize->domain) ? $personalize->domain:'', 'class' => 'form-control','placeholder' => __('e.g, mydomain.com'),'disabled'=>true]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['domain']['_empty'])) {
                                                            echo $errors['domain']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['header'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Header</label>
                            <div class="col-lg-9">
                                       <?php echo $this->Form->input('header', ['type'=>'text','label' =>false,'value'=>isset($personalize->header) ? $personalize->header:'', 'class' => 'form-control', 'placeholder' => '']); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['header']['_empty'])) {
                                                            echo $errors['header']['_empty'];
                                                        } 
                                                        ?>
                                </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['footer'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3">Footer</label>
                            <div class="col-lg-9">
                                             <?php echo $this->Form->textarea('footer', ['label' =>false,'value'=>isset($personalize->footer) ? $personalize->footer:'','rows'=>2 ,'class' => 'form-control', 'placeholder' => 'e.g, Copyright © 2020 MY Academy. All rights reserved.']); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['footer']['_empty'])) {
                                                            echo $errors['footer']['_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(__('Save'), ['type'=>'submit','class' => 'btn btn-success tab3Save pull-left btn-grid btn-flat s-btn']) ?>

                            </div>
                        </div>

                    </div>
                    <!-- /.form-group -->
                </div>

            </div>
            <!-- /.row -->
        </div>
        <!-- /.box-body -->
<?= $this->Form->end() ?>
    </div>
</div>
<script src="<?php echo $this->request->webroot;?>js/jsvalidate/jquery.validate.min.js"></script>
<script type="text/javascript">
    $('#project_form').validate({
        rules: {
            'smtp_host': 'required',
            'username': 'required',
            'password': 'required',
            'smtp_from': 'required',
            'domain':{'required':true,'domain':true},
            'email_signature':'required',
            'smtp_port': {
                'required':true,
                digits: true
            },
        },
        messages: {
            'smtp_host':{
                required: "Please enter smtp host"
            },
            'username':{
                required: "Please enter smtp username"
            },
            'password':{
                required: "Please enter smtp password"
            },
            'smtp_from':{
                required: "Please enter smtp from",
                digits: "Allow only digit"
            },
            'smtp_port':{
                required: "Please enter smtp port"
            },
            'domain':{
                required: "Please enter domain"
            },
            'email_signature':{
                required: "Please enter email signature"
            }
        },
        highlight: function (element) {
            $(element).parent().addClass("has-error");
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
    
    $('input[name=is_smtp]').click(function(){
        $('.has-required').attr('disabled',true);
        $('.has-required').attr('required',false);
        $('.error').hide();
        $('span.required').hide();
        $('.has-error').removeClass('has-error');
        if($(this).prop('checked')){
            $('span.required').show();
            $('.has-required').attr('disabled',false);
            $('.has-required').attr('required',true);
        } 
    });
    
   
</script>