<?php
include_once('c_rmt_check_s.php') ;
class c_page_cab_rmt_check_tablet extends c_page_cab_rmt_check_s
{
  public $h1='Чтение QR-кода' ;
// public $use_auto_complete=1;

 function set_head_tags()
 { parent::set_head_tags() ;
   $this->HEAD['css'][]=_PATH_TO_EXT.'/interface/ios7-switch-master/ios7-switch.css' ;
     
 }
    

 function block_main()
 { $this->page_title() ;
    $this->panel_QR_code_capture(['mode'=>'tablet']);
 }


    function panel_QR_code_capture($options=array())
    { ?>
        <div id=panel_QR_code_capture style="margin-bottom: 10px;">
            <select class="central-elements" id="camera-select" style="min-height: 36px; width: 154px;vertical-align: top;"></select>
            <button class="central-elements" id="camera-play"><i class="fa fa-play"></i></button>
            <button class="central-elements" id="camera-stop"><i class="fa fa-stop"></i></button>
        </div>
        <canvas id="video_stream" style="outline: 1px solid #000;"></canvas>
        <h2>Поднесите QR-код к камере</h2>
        <div id="panel_PL_info"></div>
        <style>
            #panel_QR_code_capture {
                /*background-color: #333;*/
                /*overflow: hidden;*/
            }
            button.central-elements {
                height: 36px;
                width: 40px;
                /*float: left;*/
                /*margin: 0;*/
                /*position: relative;*/
                /*top: 50%;*/
                /*transform: translate(0, -50%)*/
            }

        </style>
        <script type="text/javascript" src="/AddOns/webcodecamjs-master/js/qrcodelib.js"></script>
        <script type="text/javascript" src="/AddOns/webcodecamjs-master/js/webcodecamjs.js"></script>
        <script type="text/javascript">
            let arg = {
                //resultFunction: function(resText, lastImageSrc) { send_ajax_request({cmd:'rmt/ready_qr_code',mode:'<?//echo $options['mode']?>//',qr_code:resText,qr_code1:escape(resText),qr_code2:encodeURI(resText)}) ;},
                resultFunction: function(resText, lastImageSrc) { send_qrcode(resText) ;},
                width: 240,
                height: 180,
                successTimeout: 4000,
                frameRate: 8,
                beep:"<?echo _PATH_TO_EXT.'/rmt/sounds/sounds-958-thin.mp3'?>",
                decoderWorker: '/AddOns/webcodecamjs-master/js/DecoderWorker.js',
                DecodeBarCodeRate: null,
            };

            let TO_access_type;

            function send_qrcode(resText) {
                qr_decoder.stop();
                send_ajax_request({cmd:'rmt/ready_qr_code',mode:'<?echo $options['mode']?>',qr_code:resText['code'],qr_code1:escape(resText),qr_code2:encodeURI(resText)})
            }

            let qr_decoder = new WebCodeCamJS("#video_stream").buildSelectMenu('#camera-select', 'facing back').init(arg).play();

            $j('#camera-play').on('click',function(){
                qr_decoder.play();
            })

            $j('#camera-stop').on('click',function(){
                qr_decoder.stop();
            })

            $j(document).ready(function()
            {
                $j('body').everyTime(1000,'active_qr_reader',function(){
                    if (!$j('#jBox-overlay').is(':visible')) {
                        qr_decoder.play();
                    } else {
                        qr_decoder.stop();
                    }
                })
            });

        </script>
        <?
    }




 function panel_nomer()
 { ?><div id="panel_nomer">
      <?echo $this->rec_personal['_ext_info']['CarDetails']['Marka'].' '.$this->rec_personal['_ext_info']['CarDetails']['Model'].' '.$this->rec_personal['_ext_info']['CarDetails']['CarNumber']?>
     </div>
   <?
 }

 function panel_TO()
 { include_once('panel_driver_info.php');
   include_once('panel_car_info.php');
   include_once('panel_check_car.php');
   include_once('panel_MO_info.php');

   $time_mo=getdate(time()) ;
   $time_from=mktime($time_mo['hours']-8,$time_mo['minutes'],$time_mo['seconds'],$time_mo['mon'],$time_mo['mday'],$time_mo['year']);
   $rec_mo=ESMO()->get_last_mo_rec_to_personal($this->rec_personal['pkey'],array('only_model'=>'all','time_from'=>$time_from)) ;
   ?><div id="panel_TO"><form><div id="panel_image_preview"></div>
           <?$this->panel_img_mo_view();?>
           <table class="col2x">
             <tr><td class="info"><? panel_MO_info($rec_mo) ;
                                     panel_driver_info($this->rec_personal);
                                     panel_car_info($this->rec_car);
                                 ?></td>
                 <td class="krit"><? panel_check_car($this->rec_personal,$this->rec_car,$rec_mo) ; ?></td>
             </tr>
           </table>
     </form></div>
     <div class="buttons"><button class="close_window">Закрыть</button></div>
   <?
 }







}

?>