<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header"><?= $pageTitle ?></h1>
    </div>
</div>
<div class="row">

    <div class="col-md-4">
        <form action="/admin/ajax/editPannerPhotos" class="form" id="validation" method="post" enctype="multipart/form-data">
            <input type="hidden" value="<?= $id ?>" name="id" />
           
            
<?php if ($theLink != "NO") { ?>
        <br><div class="form-group">
                <h2 class="titleSelectPhoto"><?=$this->Get_Lang->gl('the_link',$adminLang)?></h2>
                <input class="form-control" type="text" id="theLink" value="<?=$theLink?>" name="theLink" placeholder="<?=$this->Get_Lang->gl('the_link',$adminLang)?>" />
        </div>
<?php } ?>
        
<div class="form-group">
        
    <h2 class="titleSelectPhoto"> <?=$this->Get_Lang->gl('the_photo',$adminLang)?> </h2>
    <div class="col-md-12">
        <br>
            <div class="col-md-12" >
                <input type="text" name="file" id="fieldID" class="form-control"
                       <?php if($thePhoto){ echo "value='".$thePhoto."'"; }else{echo 'value=""';} ?> placeholder="URL" >
            </div>
        <br>
            <div class="col-md-12">
                <br>
                <a  href="javascript:open_popup('/public/lib/responsivefilemanager/filemanager/dialog.php?type=1&popup=1&multiple=0&field_id=fieldID')" class="btn btn-primary" type="button">
                    <?=$this->Get_Lang->gl('select_photo',$adminLang)?>...(<?php if(isset($photoSize)){echo $photoSize;}?>)
                </a>
            </div>
         <?php
        if ($thePhoto != NULL) { ?>
            <br><h3 style="margin-top:50px;"><?=$this->Get_Lang->gl('current_photo',$adminLang)?></h3>
            <img width='300px' src="<?= $thePhoto ?>">
        <?php  }  ?>
    </div>
    <br>
</div>
<script type="text/javascript">
function open_popup(url)
{
        var w = 880;
        var h = 570;
        var l = Math.floor((screen.width-w)/2);
        var t = Math.floor((screen.height-h)/2);
        var win = window.open(url, 'ResponsiveFilemanager', "scrollbars=1,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

</script>



            <div class="form-group">
                <button id="saveBtn" class="btn btn-primary pull-left" type="submit"><?=$this->Get_Lang->gl("save",$adminLang)?></button>
            </div>
        </form>
    </div>

</div>
<script src="/public/lib/validation/jquery.validate.js"></script>
<script src="/public/js/jquery.form.js"></script>
<script src="/public/lib/validation/localization/messages_<?=$tlang?>.js" type="text/javascript"></script>
<script src="/public/lib/validation/localization/messages_<?=$tlang?>.min.js" type="text/javascript"></script>

<script>

                    $(".nav>li>a.panner").addClass("active");
                    $(".sidebar-dropdown.one").addClass("active");
                    $(".sidebar-wrapper .sidebar-menu ul li a.panner").addClass("active");
                    $(".sidebar-dropdown.one .sidebar-submenu").fadeIn(); 


                    $(".form").each(function () {
                        $(this).validate({
                            highlight: function (element) {
                                $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
                            },
                            unhighlight: function (element) {
                                $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                            },
                            ignore: [],
                            rules: {
                                'file': {required: true},
                            },
                            errorPlacement: function (error, element) {
                                error.insertAfter(element);
                            }
                        });
                    });


                    $(".form").ajaxForm({
                        beforeSubmit: function (arr, $form, options) {
                            $activeForm = $form;
                            if (!$form.valid())
                                return false;
                        },
                        complete: function (xhr) {
                            var response = xhr.responseText;
                            if (response == 1) {

                                $('.fileinput').fileinput('clear');
                                $("#saveBtn").prop('disabled', true);
                                setTimeout(function () {
                                    $("#saveBtn").prop('disabled', false);
                                }, 3000);

                                common.showAlert("The job done successfully", "success", 3);
                                window.open("/admin/panner_photos", "_self");
                            } else {
                                common.showAlert("Error <br>" + response, "danger", 0);
                            }
                        }
                    });



                    function fillTheForm(frm, data) {
                        $.each(data, function (key, value) {
                            var $ctrl = $('[name=' + key + ']', frm);
                            if ($('[name=' + key + ']').length > 0){
                            switch ($ctrl.attr("type"))
                            {
                                case "text" :
                                case "hidden":
                                    $ctrl.val(value)
                                    break;
                                case "radio" :
                                case "checkbox":
                                    $ctrl.each(function () {
                                        if ($(this).attr('value') == value) {
                                            $(this).attr("checked", value);
                                        }
                                    });
                                    break;
                                default:
                                    if (!$ctrl.length)
                                    {
                                        var array = $.map(value, function (v, i) {
                                            return [v];
                                        });
                                        if (array.length > $("[name='" + key + "[]']", frm).length)
                                        {
                                            addCount = array.length - $("[name='" + key + "[]']", frm).length;
                                            for (var i = 0; i < addCount; i++) {
                                                $("[name='" + key + "[]']", frm).parents(".exercise-type-div").find(".addNew").trigger("click");
                                            }
                                        }
                                        $("[name='" + key + "[]']", frm).each(function (index) {
                                            $(this).val(array[index]);
                                        });
                                    } else {
                                        $ctrl.val(value);
                                    }
                            }
                            $ctrl.change();
                        }
                        });
                    }

</script>
