<?php
include_once("c_personal_person.php");

class c_page_cab_personal_person_sv extends c_page_cab_personal_person
{
  public $h1='Карточка клиента - подписи мо' ;

 function set_head_tags()
    {  
        parent::set_head_tags() ;
    $this->HEAD['css'][]='/'._CLASS_.'/ext/aspmo_sv/style.css' ;
    $this->HEAD['js'][]='/'._CLASS_.'/ext/aspmo_sv/script.js' ;
 }

 function get_cur_page_meta_tags()
 {
   if ($this->rec_personal['pkey']) $this->h1='Подписи МО '.$this->rec_personal['obj_name'] ;
 }

 function block_main()
    { 
        $this->page_title() ;

        $res=execSQL("select mos.*, mosDTW.pkey as signature_key, mosDTW.obj_name as signature,"
                . " mosDTW.time_sign, mosDTW.point_count, mosDTW.point_per_sec "
                . " from obj_site_mo_session as mos "
             . "inner join obj_site_mo_session_DTW as mosDTW on mosDTW.parent = mos.pkey "
             . "where  mos.member_id=".$this->rec_personal['pkey']." order by mos.pkey");
     
     $colors=['#be1e2d','#666699','#92d5ea','#ee8310','#8d10ee','#5a3b16','#26a4ed','#f45a90','#e9e744'];
     $count=0;
     $rec_norm=execSQL_van("select mosDTW.* from obj_site_mo_session_DTW as mosDTW "
             . "inner join obj_site_personals as osp on osp.sign_id = mosDTW.pkey "
             . "where osp.pkey=".$this->rec_personal['pkey']);

    if (isset($rec_norm) && isset($rec_norm['obj_name'])) {
        $script_name =  signature()->save_DTW_data_to_js($rec_norm['obj_name'], $rec_norm['parent']) ;

        /*
        $st_signature = unserialize($rec_norm['obj_name']);
        $st_last_point = array_pop($st_signature);
        $st_first_point = array_shift($st_signature);
        $st_time_sign = number_format(($st_last_point['t'] - $st_first_point['t']) / 1000, 3) ;
        */
            //$st_signature = unserialize($rec_norm['obj_name']);
            //$st_count_point = $rec_norm['point_count'];//count($st_signature);
            $st_time_sign = number_format($rec_norm['time_sign'] / 1000, 3);//signature()->get_signature_time($st_signature);
            //$st_point_per_sec = $rec_norm['point_per_sec'];//($st_time_sign > 0) ? floor($st_count_point / $st_time_sign) : 0;
            
        ?>

            <script type="text/javascript" src="/tmp/<?echo $script_name?>"></script>
            <script type="text/javascript" src="/<?echo _CLASS_?>/ext/aspmo_signature/signature_renderer.js" ></script>
            <table>
            <tr>
                <td>Подпись сотрудника:
                    <br />
                    <button onclick="$j('#canvas1').signatureRender(sample1);">Обновить</button>
                </td>
                <td class="left">
                    <canvas id="canvas1" style="border: medium; border-color: #DBDBDB; border-style: solid;" width="600" height="400"> &nbsp; </canvas>
                    <script type="text/javascript">
                            $j(document).ready(function(){
                                $j('#canvas1').signatureRender(sample1);
                                $j('#canvas1').signatureTooltip( <? echo json_encode(unserialize($rec_norm['obj_name']), JSON_FORCE_OBJECT ); ?>);
                            });
                            $j(document).ready(function(){});
                    </script>
                </td>
            </tr>
            </table>
                     <? } else { ?>
        <div class="red">Эталонная подпись не назначена</div>
        <?}?>
     <form>
     <h2>Подписи клиента</h2>
     <div id="panel_list_rec_popilumetr">
     <table><tr><th>Выбор<br /> эталона</th><th>ID подписи</th><th>Дата медосмотра</th><th>ID медосмотра</th><th>Кол-во точек</th><th>Продолжительность<br /> подписи</th><th>Кол-во точек<br /> в секунду</th><th>Комментарий</th><th>Результат</th></tr>
         <? foreach ($res as $rec)
             {  //$signature = unserialize($rec['signature']);
                //$count_point = count($signature);
            /*
            $last_point = array_pop($signature);
            $first_point = array_shift($signature);
            $time_sign = number_format(($last_point['t'] - $first_point['t']) / 1000, 3) ;
            */
                $time_sign = number_format($rec['time_sign'] / 1000, 3);
                //$point_per_sec = ($time_sign > 0) ? floor($count_point / $time_sign) : 0;
            
           ?><tr id="tr_<?echo $rec['signature_key']?>" <?if (in_array($rec['signature_key'],$_POST)){?>style="background-color: <? if (!isset($_POST['calculate'])) echo $colors[$count]; else echo "#fff"; ?>;"<?$count++;}?>>
             <td><input type="radio" value="<?echo $rec['signature_key'];?>" name="use_standart" <?if ($rec_norm['pkey'] == $rec['signature_key'] && $rec['signature_key'] > 0) {echo " checked";}?>></td>
             <td class="preview_graf"><div><?echo $rec['signature_key'];?><div class="panel_preview" sv_id="<?echo $rec['pkey']?>" st_id="<?echo $rec_norm['parent'];?>" id="panel_preview_<?echo $rec['pkey']?>"></div></div></td>
             <td><?echo date('d.m.Y H:i:s',$rec['c_data'])?></td>
             <td><?echo $rec['pkey'];?></td>
                 <td><?echo $rec['point_count'];?></td>
             <td><?echo $time_sign;?></td>
                 <td><?echo $rec['point_per_sec'];?></td>
             <td><textarea class="v2" cmd="aspmo_sv/save_comment" event="change" no_send_form="1" sv_id="<?echo $rec['pkey']?>"><?echo $rec['comment']?></textarea></td>
                 <td style="background-color: <? if (isset($rec_norm) && isset($rec_norm['obj_name'])) { if ($rec['DTW_res']) { echo "green;";} else { echo "red;";} echo "color: white;";}?>">
                <? if (isset($rec_norm) && isset($rec_norm['obj_name'])) { ?>
                <a href="/cab/sv/<? echo $rec['signature_key']?>/" class="new_window">Отклонение по форме:
                <? echo  ($rec['signature_DTW_mp_Cost']) ? number_format($rec['signature_DTW_mp_Cost'], 2) : "0.00";?></a>
                <br />
                Отклонение по времени:
                    <? echo (($st_time_sign > 0) ? floor((1 -$time_sign / $st_time_sign) * 100) : 0);?>%
                <br />
                Соотношение кол-ва точек в секунду:
                    <? echo (($rec_norm['point_per_sec'] > 0) ? number_format($rec['point_per_sec'] / $rec_norm['point_per_sec'], 2) : 0);?>
                <?} else {?>
                Эталонная подпись не назначена
                <?}?>
             </td>
         </tr>
     <?}?>
     </table></div>
     <div class="buttons">
         <button class="v2" cmd=aspmo_sv/set_standart personal_id="<?echo $this->rec_personal['pkey']?>">Назначить эталоном</button>
     </div>
     </form>
     <?
 }
}
?>