<?php

?>
        <script type="text/javascript" src="/class_v2.01/ext/aspmo_narko/visualize/js/jquery.js"></script>
        <script type="text/javascript" language="JavaScript" >
            var pluginObject;
            var type;
            var dataForPrint;
            function addEvent(obj, name, func)
            {
                if (obj.attachEvent) {
                    obj.attachEvent(name, func);
                } else {
                    obj.addEventListener(name, func, false);
                }
            }


            function onScanDoneFunction(firstName,secondName,middleName,passportSeries,passportNumber,photo){
                alert(secondName+" "+firstName+" "+middleName+" "+passportSeries+" "+passportNumber);
                passportSeries=passportSeries.replace(/\s+/g, '');
                var passportNumberData="passportNumber="+passportSeries+passportNumber+"&photo="+photo;
                jQuery.ajax(jQuery.ajax({
                    dataType: "json",
                    type:"POST",
                    async:false,
                    url: "/ajax.php?cmd=aspmo_authorization/getRequestData",
                    data: passportNumberData,
                    success: function(data) {
                        if ((data.requestPkey==null)||(data.requestPkey=="null")||(data.requestPkey==""))
                        {  errorMessage("заявка не найдена");}
                        if ((data.permission==0))
                        {   errorMessage("заявка не одобрена");}
                        else
                        {
                            dataForPrint={"fields":{"ОРГАНИЗАЦИЯ":data.job,
                                "ИМЯ":data.firstName,
                                "ФАМИЛИЯ":data.lastName,
                                "ОТЧЕСТВО":data.middleName,
                                "ДОЛЖНОСТЬ":data.position},
                                "passNumber":data.QRCode};
                        }


                    },
                    error: function(jqXHR, textStatus, errorThrown)
                    {

                    }
                }));
                $("#selectActionScan").css("display","none");
                $("#selectActionPrint").css("display","block");
            }


            $(document).ready(function(){
                pluginObject = document.getElementById( 'AuthorizationPlugin' );
                pluginObject.initialize();
                addEvent(pluginObject, 'onScanDone', onScanDoneFunction);
            });
            function startScan()
            {
                pluginObject.startScan();
            }



            function printQR(inputData)
            {
                var passNumber=inputData['passNumber'];
                var textForQR;
                var num=0;
                for(var key in inputData.fields)
                {
                    if(num==0)
                        textForQR=key+": "+inputData.fields[key]+"\n";
                    else
                        textForQR+=key+": "+inputData.fields[key]+"\n";
                    num++;
                }
                pluginObject.generateQR(passNumber);
                pluginObject.printQR(textForQR);
                //document.getElementById("printQRCode").disable();
            }

            function onSelectedTypeGuest()
            {
                type="guest";
               //$("#selectAction").
                $("#selectAction").css("display","block");
                $("#selectActionScan").css("display","block");
                $("#selectActionPrint").css("display","none");
                $("#selectType").css("display","none");
            }

            function onSelectedTypeWorker()
            {
                errorMessage("Функция не поддерживается");
            }

            function OnSelectedActionScan()
            {
                //startScan();
                onScanDoneFunction("1","2","3","1 2","345");
            }

            function OnSelectedActionPrint()
            {
                printQR(dataForPrint);
                $("#selectActionPrint").css("display","none");
                $("#selectActionScan").css("display","none");
                $("#selectType").css("display","block");


            }

            function errorMessage(message)
            {
                $("#info").css("display", "block");
                $("#info").html("Ошибка! <br>"+message);
                setTimeout(function(){
                    $("#info").css("display", "none");
                    $("#selectActionPrint").css("display","none");
                    $("#selectActionScan").css("display","none");
                    $("#selectType").css("display","block");
                }, 4000);

            }


        </script>
        <object id="AuthorizationPlugin" type="application/x-authorization" width="2" height="2">
            <param name="onload" value="pluginLoaded" />
        </object><br />
        <div id="main" style="text-align: center;">
            <div id="selectType">
                <div id="selectTypeGuest" onclick="onSelectedTypeGuest()"  style="cursor: pointer; background-color: #eee; margin:10px; width: 400px; height:250px; text-align: center; vertical-align: middle;"> Гость </div><br>
                <div id="selectTypeWorker" onclick="onSelectedTypeWorker()" style="cursor: pointer; background-color: #eee; margin:10px; width: 400px; height:250px; text-align: center; vertical-align: middle;"> Сотрудник </div>
            </div>
            <div id="selectAction" style="display: none;">
                <div id="selectActionScan" onclick="OnSelectedActionScan()" style="text-align: center; vertical-align: middle; background-color: #eee; margin:10px; cursor: pointer; width: 400px; height:250px;"> Отсканировать  </div><br>
                <div id="selectActionPrint" onclick="OnSelectedActionPrint()" style="text-align: center; vertical-align: middle; background-color: #eee; margin:10px; cursor: pointer; width: 400px; height:250px;">Распечатать QR  </div><br>
            </div>
            <br>
            <div id="info"style="background-color:#cf867e;top:0; margin: 10% 15%; position:absolute; display: none; width:70%; height:400px"> </div>
        </div>
