
<div class="row">



    <div class="container" >
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li class="active">تست الحسابات</li>
        </ol>


        <div class="row" id="mainDiv_uga">


            <div class="container" style="padding: 0px 15px;">
                <div class="panel panel-default panel-m row">
                    <div class="panel-heading">
                        <h3 class="panel-title">تست الحسابات</h3>
                    </div>
                    <div class="panel-body">



                        <div class="col-lg-5 col-lg-offset-4">
                            <div class="panel panel_login">
                                <div class="panel-heading loginpanel">
                                    <h3 class="panel-title">تأكيد الصلاجيات وقاعدة البيانات</h3>
                                </div>
                                <form class="form-horizontal" id="uga-login-form">
                                    <div class="form-group">
                                        <label for="password" class="col-lg-4 control-label">كلمة المرور</label>
                                        <div class="col-lg-8">
                                            <input type="password" class="form-control" id="password" name="password" placeholder="كلمة المرور" autocomplete="new-password"<!-- autocomplete="new-password" this to stop writing user name in next field which is "db"-->
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="col-lg-4 control-label">قاعدة بيانات التست</label>
                                        <div class="col-lg-8">
                                            <select name="db" id="db" class="select2 wdt100" placeholder="اختر قاعدة البيانات">
                                                <option value="-1" selected="selected">--قاعدة بيانات جديدة--</option>
                                                {assign var=bar value=1}
                                                {section name=i loop=$databases}
                                                <option value="{$databases[i]}" {*  if $bar == 1}selected="selected" {/if  *}>{$databases[i]}</option>
                                                {assign var=bar value=$bar+1}
                                                {/section}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group" id="newdbnameDiv">
                                        <label for="password" class="col-lg-4 control-label">اسم قاعدة البيانات الجديدة </label>
                                        <div class="col-lg-8">
                                            <input type="text" class="form-control" id="newdbname" name="newdbname" placeholder="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-lg-offset-2 col-lg-10">
                                            <span id="newdbNote" style="display: none;font: 18px solid blue; background-color: #aaecab; border-radius: 11px; padding: 1px 5px;margin-right: 27px; border: 1px solid black!important;">جارى انشاء قاعدة البيانات يرجى الانتظار</span>
                                            <button type="submit" id="uga-go-btn" class="btn btn-default pull-left submit color-white">متابعة</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>




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



        </div>



    </div>
</div>

{literal}
<script type="text/javascript">
    var attempts = 0;
    $('#uga-login-form').live('submit', function (e) {
        e.preventDefault();
        e.stopPropagation();
        var thisis = $(this);
        if (!thisis.hasClass('processing...')) {
            thisis.addClass('processing...');

            var db = $('#db').val();
            if (db == "-1" && $('#newdbname').val() == "") {
                $('#newdbname').css('background-color', 'yellow');
                thisis.removeClass('processing...');
            } else {
                $('#newdbname').css('background-color', 'white');

                if ($('#password').val() == "") {
                    $('#password').css('background-color', 'yellow');
                    thisis.removeClass('processing...');
                } else {
                    $('#password').css('background-color', 'white');


                    //setTimeout to let html changes done and seen
                    setTimeout(function () {
                        $.ajax({
                            type: "POST",
                            url: 'automationtest.php?do=en',
                            data: {db: db, newdbname: $('#newdbname').val(), password: $('#password').val()},
                            async: false,
                            success: function (data) {
                                thisis.removeClass('processing...');
                                if (data == -1) {
                                    attempts = attempts + 1;
                                    if (attempts < 3) {
                                        $('#password').css('background-color', '#d43f3a');
                                        setTimeout(function () {
                                            $('#password').css('background-color', 'white');
                                            $('#password').val("");
                                        }, 2000)
                                    } else {
                                        window.location.href = 'logout.php';
                                    }
                                } else if (data == -2) {
                                    alert('ناكد من اختيار فاعدة البيانات');
                                } else {
                                    if (db == "-1") {
                                        $('#newdbNote').show();
                                        $('#currentDBName').text($('#newdbname').val());
                                    }
                                    $('#mainDiv_uga').html(data);
                                }

                            }

                        });
                    }, 0);
                }
            }
        }
    });
    $('#db').live('change', function (e) {
        var db = $('#db').val();
        var newdbname = $('#newdbname').val();
        if (db == "-1") {
            $('#newdbnameDiv').show();
        } else {
            $('#newdbnameDiv').hide();
        }

    });
</script>
{/literal}