<?php
include_once("c_setting_config.php");
class c_page_cab_setting_config_handsign extends c_page_cab_setting_config
{
  public $h1='Настройка ручной подписи' ;

 function block_main()
 { $this->page_title() ;
   ?><form><table class="basic fz_small auto left full">
         <? $this->form_element_input('Минимальное число непрырывных линий','','LS_handsign_line_min') ; ?>
         <? $this->form_element_input('Минимальное число точек в линии','','LS_handsign_pix_min') ; ?>
         <tr><td colspan="2" class="right"><button class="v2" cmd="aspmo_setting/save_setting">Сохранить</button></td></tr>
     </table></form><br>
     <?

   $this->panel_person_sign() ;


 }

   function panel_person_sign()
   {   ?><!--[if lt IE 9]><script type="text/javascript" src="/AddOns/jSignature/flashcanvas.js"></script><![endif]-->
         <script src="/AddOns/jSignature/jSignature.min.noconflict.js"></script>
         <div id="panel_person_sign">
                <table id="table_person_sign"><tr>
                          
                         <td class=item>
                             <div id="signature" style="width:800px;height:200px;"></div>
                         </td>
                         <td class=item style="vertical-align:middle;">
                             <div id="alert"></div>
                         </td>
                    </tr>
                   </table>
                   <script type="text/javascript">
                       $j(document).ready(function() { $j("#signature").jSignature({color:"#00f",'decor-color':'#ffffff',showLine:0}) ; }) ;
                   </script>
                   <div class="sky-form" style="text-align:center;">
                       <div class="center">
                        <button style="width:300px;height:70px;float:left;" id="apply_sign" class="button">Проверка</button>
                      </div>
                   </div><div class="clear"></div><br>
                 <p>Число линий <strong id="line_cnt">-</strong></p>
                 <p>Число точек в линии: <strong id="pix_cnt">-</strong></p>
                 <h2>Цифровое представление подписи:</h2>
                 <textarea id="sign_info2"></textarea>


         </div>
         <style type="text/css">
            #table_person_sign{width:auto;table-layout:auto;}
            #table_person_sign td{text-align:left;vertical-align:top;padding-right:20px;}
            #table_person_sign td.item img{border:1px solid #aaaaaa;float:left;}
            #table_person_sign td.item .name{font-size:16px;font-weight:bold;}
            #table_person_sign td.item div.org_name{font-size:13px;}
            #table_person_sign td.item div.otdel_name{font-size:11px;}
            #table_person_sign td.item div.working_name{font-size:11px;margin-bottom:12px;}
            #table_person_sign div#signature{width:800px;height:200px;margin-top:20px;background:url("<?echo _PATH_TO_EXT?>/esmo_magnit_instruction/img/kletka.png") repeat;}
            #sign_info2{width:100%;height:300px;margin-top:20px;}
            div#sign_stats strong{font-size:18px;}
            div#alert{font-size:22px;color:green;}
            div#alert div.success{font-size:22px;color:green;}
            div#alert div.failed{font-size:22px;color:red;}
         </style>
         <script type="text/javascript">
             $j('button#apply_sign').on('click',function()
             {  var sigdiv = $j("#signature")
                var datapair = sigdiv.jSignature("getData", "native")  ;
                var cnt_line=datapair.length ;
                var cnt_pix=0 ;
                $j.each(datapair,function(id,value){if (value.x.length>cnt_pix) cnt_pix=value.x.length;})
                $j('#sign_info2').val(JSON.stringify(datapair)) ;
                $j('#line_cnt').html(cnt_line) ;
                $j('#pix_cnt').html(cnt_pix) ;
                if (check_handsign(datapair)) $j('#alert').html('<div class=success>Подпись корректна</div>') ;
                else $j('#alert').html('<div class=failed>Подпись некорректна</div>') ;
                $j('body').oneTime(3000,'check_handsign_clear',function(){$j('#alert').html('') ;})

             }) ;

             function check_handsign(datapair)
             {   var cnt_line=datapair.length ;
                 var cnt_pix=0 ;
                 $j.each(datapair,function(id,value){if (value.x.length>cnt_pix) cnt_pix=value.x.length;}) ;
                 var min_line=<?echo $GLOBALS['LS_handsign_line_min']?> ;
                 var min_pix=<?echo $GLOBALS['LS_handsign_pix_min']?> ;
                 if (cnt_line>=min_line && cnt_pix>=min_pix) return(1) ;
                 else                                        return(0) ;

             }
         </script>
       <?
   }




}



?>