<head>
    <title>برنامج البسيط للمحاسبة</title>
    <meta charset="utf-8">
</head>
<form id="sql_form" class="form-horizontal" method="post" enctype="multipart/form-data">
    <input type="file" name="pfile" id="pfile" accept=".sql,.txt"/>
    <button type="button" id="run_sql">GO</button>
    <div id="results"></div>
</form>
<footer>

    <script type="text/javascript" charset="utf-8" src="media/js/jquery.js"></script>
    {literal}
    <script>
        $('#pfile').change(function (e)
        {
            if ($('#pfile').val() != "") {
                var uploadedFile = $(this).val();
                var file = uploadedFile.toLowerCase();
                var fileExtension = file.substring(file.lastIndexOf('.') + 1);
                //var allowedExtensions = ['doc', 'docx', 'pdf', 'jpg', 'jpeg', 'png', 'gif'];
                var allowedExtensions = ['sql', 'txt'];
                if ($.inArray(fileExtension, allowedExtensions) > -1)
                {
                    //ok
                }
                else
                {
                    $('#pfile').val("");
                    alert('مسموح بملفات sql و txt فقط');
                }
            }

        });
        $('#run_sql').click(function ()
        {
            if ($('#pfile').val() != "") {
                $('#run_sql').hide();
                $("#sql_form").submit();
            } else {
                alert('لم تختر ملف');
            }

        });
        $("#sql_form").on('submit', (function (e) {
            e.preventDefault();
            //return false;
            $('#results').html("");

            $.ajax({
                url: 'restoredaybackup.php?do=runsql', // Url to which the request is send
                type: "POST", // Type of request to be send, called as method
                data: new FormData(this), // Data sent to server, a set of key/value pairs representing form fields and values
                contentType: false, // The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded"
                cache: false, // To unable request pages to be cached
                processData: false, // To send DOMDocument or non processed data file it is set to false (i.e. data should not be in the form of string)
                success: function (data)  		// A function to be called if request succeeds
                {
                    $('#run_sql').show();
                    $('#results').html(data);
                }
            });
        }));
    </script>
    {/literal}
</footer>
