<?php // $cs = Yii::app()->getClientScript();           ?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'user-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
        ));
?>

<div class="tab-content">
    <div class="tab-pane active">

        <ul class="clearfix form-ul material">

            <?php
            echo $form->hiddenField($model, 'id');
            $readonly = false;
            if ((int) $model->id > 0) {
                // $readonly=true;
                $readonly = false;
            }
            ?>


            <li class="col-sm-3">
                <?php echo $form->textField($model, 'first_name', array('data-label' => 'First Name <span style="color:red">*</span>', 'data-validation' => 'required', 'readonly' => $readonly)); ?>
            </li>
            <li class="col-sm-3">
                <?php echo $form->textField($model, 'last_name', array('data-label' => 'Last Name <span style="color:red">*</span>', 'data-validation' => 'required', 'readonly' => $readonly)); ?>
            </li>

       
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->dropdownList($model, 'level', array("1" => "Admin", "3" => "Branch", "4" => "Sales"), array('data-label' => 'Login Level <span style="color:red">*</span>', 'data-validation' => 'required')); ?>
            </li>
            
            <li class="col-sm-3">

                <?php echo $form->dropdownList($model, 'user_group_id', MasUserGroup::getUserGroup(), array('data-label' => 'User Group <span style="color:red">*</span>', 'data-validation' => 'required', 'prompt' => '--Select--')); ?>
            </li>
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->textField($model, 'designation', array('data-label' => 'Designation')); ?>
            </li>
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->textField($model, 'phno', array('data-label' => 'Phone Number <span style="color:red">*</span>', 'data-validation' => 'required')); ?>
            </li>
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->textField($model, 'email', array('data-label' => 'Email <span style="color:red">*</span>', 'data-validation' => 'required')); ?>
            </li>

            <li class="col-sm-3">
                <?php
                 $read_only = false;
               /* if ($model->id > 0 && $model->available_warehouses!='') {
                    //$read_only = true;
                    $model->available_warehouses=explode(',',$model->available_warehouses);
                }*/
                   echo $form->dropdownList($model, 'warehouse_id', MasInventoryWarehouse::getWarehouses(), array('data-label' => 'Warehouse <span style="color:red">*</span>','data-validation' => 'required', 'data-search' => true, 'disabled' => $read_only));

                //echo $form->dropdownList($model, 'available_warehouses', MasInventoryWarehouse::getWarehouses(), array('data-label' => 'Warehouse <span style="color:red">*</span>', 'prompt' => '--Select--'));
                ?>
            </li>
            <li class="col-sm-3">

                <?php echo $form->dropdownList($model, 'is_lead_owner', array("Y" => "Yes", "N" => "No"), array('data-label' => 'Is Sales Man <span style="color:red">*</span>', 'data-validation' => 'required')); ?>

            </li>
            <li class="col-sm-3">
                <?php echo $form->textField($model, 'username', array('data-label' => 'User Name <span style="color:red">*</span>', 'data-validation' => 'required')); ?>
            </li>


            <li class="col-sm-3">
                <?php
                $model->password = '';
                echo $form->passwordField($model, 'password', array('data-label' => 'Password <span style="color:red">*</span>', 'data-validation' => 'required', 'onclick' => 'getpassword(this.val);', 'onfocus' => 'getpassword(this.val);', 'onblur' => 'setpassword(this.val);'));
                ?>
                <?php echo CHtml::hiddenField('hid_password', $model->password); ?>
            </li>
            <li class="col-sm-3">

            <?php echo $form->dropdownList($model, 'connected_employee_id', array(), array('data-label' => 'Connected Employee', 'data-validation' => 'required')); ?>

            </li>
            
            <li class="col-sm-6" style="display:none;">
                <?php
                echo $form->labelEx($model, 'Signature(Max Size-30Kb-150W X 200H px)');
                $allowedExtensions = array("png", "jpg", "jpeg");
                $this->widget('ext.EAjaxUpload.EAjaxUpload', array(
                    'id' => rand(),
                    'config' => array(
                        'action' => Yii::app()->createUrl(Yii::app()->controller->id . '/UploadSignature', array('folder' => 'uploads/signature')),
                        'multiple' => false,
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 30 * 1024, //30kb
                        'onStart' => "js:function(){}",
                        'onComplete' => "js:function(id, fileName, responseJSON){
                                                              $('#User_signature').val(responseJSON.filename);
                                                              $('#div_signature_photo').html('<img width=\'100\' height=\'100\' src=\"" . Yii::app()->baseUrl . "/uploads/signature/'+responseJSON.filename+'\" />')
                                                       }",
                    )
                ));
                ?>
                <div class="each_image1">
                    <?php if ($model->id && $model->signature != ''): ?>
                        <div id="div_signature_photo" class="each_image">
                            <img id="img_signature__photo" src="<?php echo Yii::app()->baseUrl; ?>/uploads/signature/<?php echo $model->signature; ?>" width='100' height='100' />
                        </div>
                    <?php endif; ?>
                    <?php echo $form->hiddenField($model, 'signature'); ?>
                </div>

            </li>
            
            <li class="col-sm-6" style="display:none;">
                <?php
                $technician_model = new Technician();
                echo $form->dropDownList($model, 'technician_id', $technician_model->getTechnician(), ['empty' => 'select', 'data-label' => 'Connected Technician']);
                ?>

            </li>
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->textField($model, 'commission', array('data-label' => 'Commission')); ?>
            </li>
            <li class="col-sm-6" style="display:none;">
                <?php echo $form->textField($model, 'staff_id', array('data-label' => 'Staff ID')); ?>
            </li>
            <li class="col-sm-12"></li>
                          <fieldset class="box-style-1">
                            <legend>HR Settings</legend>
                             <li class="col-sm-6"> 
                             <?php echo $form->dropdownList($model, 'hr_connected_employee_id', Employee::getEmployee(), array('data-label' => '<span style="color : red;"> Employee(* Connect with HR For Admin Access)</span>', 'data-search' => 'true','empty'=>'Select')); ?>
                             
                <?php 
                $model->branch_id="";
                if(!empty($model)){
                $model->branch_id=explode(',',$model->branch_id);
                }
                ?>
                </li>
                 <li class="col-sm-6"> 
                <?php 
                echo $form->dropdownList($model, 'branch_id', MasCompanyBranchSponsor::getCompanyBranchesForUser(),array('data-label'=>'Branch<span style="color:red"> *</span>','data-search'=>'true','multiple'=>'true')); ?>
                </li>
                        </fieldset>     
            

        </ul>
    </div>

</div>
<div class="modal-footer">
    <button type="button" class="btn btn-danger" id="user_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('users/SaveUsers');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
                                    $("#loader").hide();
                                    if(data.status=="success"){
                                         t8.success("User Saved Successfully!");
                                         $("#user_close").click();
                                        //location.reload();
                                        reloadTable("#tbl_user_details");
                                    } else {
                                        $("#user-form .user-save-btn").prop("disabled", false);
                                        $("#user-form .user-save-btn").addClass("btn-theme").removeClass("btn_loding");
                                        $.each(data, function(key, val) {
                                                $("#user-form #"+key+"_em_").text(val).show();
                                                t8.error(""+val+"");
                                        });
                                    }
                            }',
        'beforeSend' => 'function(){
                                $("#loader").show();
                                $("#user-form .user-save-btn").prop("disabled", true);
                                $("#user-form .user-save-btn").addClass("btn_loding").removeClass("btn-theme");
                                $(".toast8-error").hide();
                            }',
        'complete' => 'function(){
                                $("#loader").hide();

                            }'
            ), array('id' => 'mybtn' . rand(), 'class' => 'user-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>
<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("getpassword", "function getpassword(value)
    {
        var user_password = $('#hid_password').val();
        $('#User_password').val('');
    }", CClientScript::POS_HEAD);
$cs->registerScript("setpassword", "function setpassword()
    {
        var user_password = $('#hid_password').val();
        var new_password = $('#User_password').val();
        if(new_password=='')
        {
            $('#User_password').val(user_password);
        }
    }", CClientScript::POS_HEAD);
