<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_esmo_magnit_pdd_scan extends c_page
{
  public $h1='Обработка скана документа' ;
  public $rec_personal=array() ;
  public $rec_scan=array() ;
  public $rec_doc=array() ;
  public $valid_image_format=0 ;
  public $count_pages=0 ;
  public $read_only=0 ;

 //function check_access() { return(1) ;}

 function select_obj_info()
 { //damp_array($this->filter,1,-1) ;
   if (_CUR_ID)
   { $this->rec_scan=DOCS()->get_scan_by_id(_CUR_ID) ;
     if (!$this->rec_scan['pkey']) $this->result=404 ;
     else
     {  //if ($this->rec_scan['parent']!=1 and $this->rec_scan['status']==5) $this->rec_scan['status']=6 ;


        if ($this->rec_scan['personal_id']) $this->rec_personal=PERSONAL()->get_personal_by_id($this->rec_scan['personal_id']) ;
        if (!$this->rec_personal['pkey']) $this->rec_scan['personal_id']=0 ; // если в скане указан несуществующий сотрудник
        if ($this->rec_scan['doc_id']>0)    $this->rec_doc=DOCS()->get_doc_by_id($this->rec_scan['doc_id']) ;

        // проверяем не пакет ли это и общее число страниц в пакете
        if ($this->rec_scan['parent']==1) $this->count_pages=execSQL_value('select count(pkey) from obj_site_scan where parent='.$this->rec_scan['pkey'])+1 ;
        else                              $this->count_pages=execSQL_value('select count(pkey) from obj_site_scan where parent='.$this->rec_scan['parent'])+1 ;
        if ($this->count_pages>1) $this->h1.=', страница '.$this->rec_scan['indx'].' из '.$this->count_pages ;

        // проверяем что файл - изображение
        if (file_exists(_DIR_TO_ROOT.$this->rec_scan['obj_name']))
        { $fsize=filesize(_DIR_TO_ROOT.$this->rec_scan['obj_name']) ;
          $this->rec_scan['_file_size']=$fsize ;
          if ($fsize>100) // jpeg не может быть менее 100 байт
          { try
            { // имитация не-изображения для проверки перехвата (удалить после теста): добавьте в URL ?test_not_image=1
              if (!empty($_GET['test_not_image'])) throw new ImagickException('no decode delegate for this image format');
              $images = new Imagick();
              $images->readImage(_DIR_TO_ROOT.$this->rec_scan['obj_name']);
              $mime=$images->getImageMimeType() ;
              if ($mime=='image/jpeg') $this->valid_image_format=1 ;
            }
            catch (ImagickException $e) { $this->valid_image_format=0 ;}
          } else $this->valid_image_format=0 ;
        } else $this->valid_image_format=0 ;

        //// если изображение корректно и
        //if ($this->valid_image_format and !$this->rec_personal)

        $this->read_only=(MEMBER()->rol==1 and $GLOBALS['LS_scan_allow_scan_working_only_admin'])? 0:1 ;
     }
   } else $this->result=404 ;

 }


 function menu_config()
 { // вкладки для сотрудника
   if ($this->rec_scan['pkey'])
      { $this->menu[$this->rec_scan['__href']]='Обработка' ;
        $this->menu[$this->rec_scan['__href'].'log/']='История' ;
        $this->menu[$this->rec_scan['__href'].'db/']='Исходные данные' ;
        $this->page_type='window' ;
      }
   else parent::menu_config() ;
 }


 function block_main()
 { $this->page_title() ;
   ?><table class="work_area">
           <tr>
             <td class="tdcol"><?if ($this->valid_image_format) $this->panel_img() ;
                               else $this->panel_alert_not_valid_img() ;
                              ?>
             </td>
             <td class="tdcol"><div id="panel_scan_info">
                 <? $this->panel_scan_info_view() ;
                    if ($this->valid_image_format and $this->rec_scan['status']==6)
                    { $this->panel_JS_capture_img() ;
                      $this->panel_scan_capture_repeat() ;
                      $this->panel_search_personals() ;
                    }

                     if ($this->rec_personal['pkey']) $this->panel_card_personal_view() ;
                     if ($this->rec_doc['pkey']) $this->panel_card_doc_view() ;
                     else $this->panel_card_scan_source_view() ;
                     if ($this->rec_personal['pkey'])
                     {
                       $this->panel_cur_group_medic_view() ;
                       if ($this->rec_scan['status']==3 or $this->rec_scan['status']==4 or $this->rec_scan['diagnoz'] or $this->rec_scan['comment'])  $this->panel_view_diagnoz() ;
                       if ($this->rec_scan['status']==2 and $this->rec_scan['account_work']==MEMBER()->id)
                       { // если указан объект связанный с данным сообщением - дергаем его
                         //damp_array($this->rec_doc) ;

                         // в докуменах попадаются документы, не связанные с мероприятием
                         if ($this->rec_doc['pkey']) $rec_event_pass=execSQL_van('select * from obj_site_events_pass where doc_id='.$this->rec_doc['pkey']) ; else $rec_event_pass=array() ;
                         if ($rec_event_pass['pkey'])
                         { $rec_event=EVENTS()->get_event_by_id($rec_event_pass['event_id']);
                           if ($rec_event['ext']) update_rec_in_table('obj_site_docs',array('source_obj'=>$rec_event['ext'],
                                                                                            'source_pkey'=>$rec_event_pass['pkey'],
                                                                                            'source_tkey'=>$rec_event_pass['tkey']
                                                                                            ),'pkey='.$this->rec_doc['pkey']) ;
                           $this->rec_doc=DOCS()->get_doc_by_id($this->rec_doc['pkey']) ;
                         }

                         // показать панель приема документа п
                         if ($this->rec_doc['source_obj']) ENGINE()->on_event_obj($this->rec_doc,'on_scan_doc_OCR',array('scan_id'=>$this->rec_scan['pkey'],'personal_id'=>$this->rec_personal['pkey'])) ;
                         elseif ($this->rec_scan['source_obj']) ENGINE()->on_event_obj($this->rec_scan,'on_scan_doc_OCR',array('scan_id'=>$this->rec_scan['pkey'],'personal_id'=>$this->rec_personal['pkey'])) ;
                         else
                         { echo '<strong class="red">Данный документ не зарегистрирован в мероприятии "Сдача документа", если не будет выбран тип документа доступен прием скана только на стандартных условиях (добавить комментарий и заблокировать/снять блокировку по МО)</strong><br>' ;
                           $this->panel_other_docs() ;
                           $this->scan_doc_OCR_default() ;
                         }
                         //else $this->panel_set_diagnoz() ;
                       }
                     }

                     if ($this->rec_scan['account_work']==MEMBER()->id or MEMBER()->rol==1)
                     {  // echo $this->rec_scan['personal_id'] ;
                         // 3=>'Принят', 4=>'Отклонен',
                         //if ($this->rec_scan['status']==3 or $this->rec_scan['status']==4) $this->panel_change_diagnoz_button() ;
                         if ($this->rec_scan['diagnoz']) $this->panel_change_diagnoz_button() ;
                       // если не удалось распознать qr-код (doc_id=-1) и не определен сотрудник (personal_id=0) и нормальный формат изображения - показываем кнопку "распознать еще раз"
                       //if (
                       //        ($this->rec_scan['doc_id']==-1 and !$this->rec_scan['personal_id'])
                       //    or  (!$this->rec_scan['personal_id'] and $this->rec_scan['parent']!=1)
                       //
                       //    /* and $this->valid_image_format*/) $this->panel_scan_capture_repeat() ;

                         if (!$this->rec_scan['personal_id']/* and $this->rec_scan['parent']!=1*/) $this->panel_scan_capture_repeat() ;
                     }
                     /*elseif (MEMBER()->rol==1 and $this->rec_scan['personal_id']) {?><button class="button v2" cmd="esmo_magnit/ScanCaptureRepeat"  scan_id="<?echo $this->rec_scan['pkey']?>" url_page="<?echo _CUR_REPORT_DIR?>">Распознать повторно</button><?}*/

                     /*echo 'doc_source_obj='.$this->rec_doc['source_obj'].'<br>' ;
                     echo 'scan_diagnoz='.$this->rec_scan['diagnoz'].'<br>' ;
                     echo 'scan_personal_id='.$this->rec_scan['personal_id'].'<br>' ;
                     echo 'scan_status='.$this->rec_scan['status'].'<br>' ;
                     echo 'scan_account_work='.$this->rec_scan['account_work'].'<br>' ;*/

                     // если документ не распознан
                     if (/*$this->rec_scan['account_work']==MEMBER()->id and */!$this->rec_scan['personal_id'] and $this->valid_image_format and $this->rec_scan['status']!=6 and !$this->read_only)
                         $this->panel_search_personals() ;

                 ?>
                 </div>
             </td>
           </tr>
       </table>
     <?
     //$this->panel_scan_debug_info() ;
     ?>
       <style type="text/css">
            table.basic{margin-top:0;}
            table.work_area td.tdcol{vertical-align:top;text-align:left;padding-left:20px;}
            div#panel_img{border:1px solid #aaaaaa;
              -webkit-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.75);
              -moz-box-shadow:    0px 0px 5px 0px rgba(50, 50, 50, 0.75);
              box-shadow:         0px 0px 5px 0px rgba(50, 50, 50, 0.75);
            }
           div#panel_search_personals{margin-top:20px;}
           div#panel_JS_capture_img{margin-top:20px;}
           div#panel_cur_group_medic_view{background:#eeeeee;padding:5px 10px 10px 10px;margin-bottom:20px;}
           div#panel_JS_capture_img div.info{text-align:center;}
           div#panel_filter .sky-form{margin-top:20px;}
           div#panel_filter .sky-form fieldset{padding:0;margin:0;}
       </style>
     <?

   ?><br><br>
     <script type="text/javascript">
         window.opener.location.reload() ;  // перегружаем основное окно после каждого обновления дочернего окна
     </script>

     <?


 }

function scan_doc_OCR_default()
{
   ?><div id="panel_set_diagnoz"><div id="panel_filter">
                <form id="sky-form" class="sky-form">
                     <fieldset>
                         <div class="clear">
                             <section>
                                 <label class="label">Ваш комментарий к документу:</label>
                                 <label class="textarea" style="width:100%;"><textarea name="comment"></textarea></label>
                             </section>
						 </div>
                         <h3>После обработки документа:</h3><br>
                         <div>
                             <section class="col col-6">
                                 <label class="radio"><input type="radio" name="action_after" value="1" checked ><i></i> Снять ограничение на прохождение МО</label>
                             </section>
                             <section class="col col-6">
                                 <label class="radio"><input type="radio" name="action_after" value="2"><i></i> Заблокировать дальнейшее прохождение МО</label>
                             </section>
                         </div>

                     </fieldset>
					<div id="panel_buttons">
						<button class="button v2" cmd="esmo_magnit/ScanCaptureApply" personal_id=<?echo $this->rec_personal['pkey']?> scan_id="<?echo $this->rec_scan['pkey']?>">Принять</button>&nbsp;&nbsp;<??>
                        <button class="button v2" cmd="esmo_magnit/ScanCaptureCancel" scan_id="<?echo $this->rec_scan['pkey']?>">Отклонить</button>&nbsp;&nbsp;
                        <button class="button v2" cmd="esmo_magnit/ScanPersonClear"  scan_id="<?echo $this->rec_scan['pkey']?>" url_page="<?echo _CUR_REPORT_DIR?>">Сбросить сотрудника</button>&nbsp;&nbsp;
                    </div>
                 </form>
         </div>
    </div>
  <?
}

 function panel_img()
 {   ?><link rel="stylesheet" type="text/css" href="<?echo _PATH_TO_EXT?>/esmo_magnit/style.css" charset="utf-8">
         <!--<script type="text/javascript" src="/AddOns/zoom-master/jquery.zoom.min.js"></script>-->
         <div id="panel_img">
           <img id="doc_image" src='<?echo $this->rec_scan['obj_name']?>?r=<?rand(1,5000)?>' width='600' />
         </div>
       <br>
       <div id="img_action" class="sky-form no_box_shadow">
           <? // если несколько страниц - кнопка для выделения страницы из пакета
              if ($this->count_pages>1){?><button class="button v2" cmd="esmo_magnit/ScanExlude"  scan_id="<?echo $this->rec_scan['pkey']?>">Выделить лист в отдельный скан</button><?}
           ?>
           <?if (!$this->read_only){?>
           <button class="button rotate_r v2" cmd="esmo_magnit/rotate_r_image" scan_id="<?echo $this->rec_scan['pkey']?>"><i class="fa fa-repeat" aria-hidden="true"></i></button>
           <button class="button rotate_l v2" cmd="esmo_magnit/rotate_l_image" scan_id="<?echo $this->rec_scan['pkey']?>"><i class="fa fa-undo" aria-hidden="true"></i></button>
           <?}?>
           <button class="button print" id="print_doc_over_window" href="<?echo $this->rec_scan['obj_name']?>"><i class="fa fa-print" aria-hidden="true"></i></button>

           <div class="clear"></div>
       </div>
       <?  $list_images=execSQL('select * from obj_site_scan where (parent='.$this->rec_scan['pkey'].' or pkey='.$this->rec_scan['parent'].') and clss=218',0,1) ;
       ?><div id="panel_second_images"><?
       if (_sizeof($list_images)) foreach($list_images as $i=>$rec_image)
       {  ?><div class="item"><a href="/window/esmo_magnit/pdd/scan/<?echo $rec_image['pkey']?>/"><img src="<?echo $rec_image['obj_name']?>" width="200"></a><div class="title">Страница <?echo $rec_image['indx']?></div> </div><?

       }
       ?></div><?


       ?>



        <script type="text/javascript">
            /*$j(document).ready(function(){
                $j('img#doc_image')
                   .wrap('<span style="display:inline-block"></span>')
                   .css('display', 'block')
                   .parent()
                   .zoom();

            });    */
        </script>
        <style type="text/css">
            div#img_action{position:relative;width:100%;height:30px;}
            div#img_action div.title{float:left;height:20px;font-size:14px;}
            div#panel_second_images{}
            div#panel_second_images{margin-top:30px;}
            div#panel_second_images div.item{float:left;margin:15px;}
            div#panel_second_images div.item img{-webkit-box-shadow: 0px 0px 14px 0px rgba(50, 50, 50, 0.75);
            -moz-box-shadow:    0px 0px 14px 0px rgba(50, 50, 50, 0.75);
            box-shadow:         0px 0px 14px 0px rgba(50, 50, 50, 0.75);}
            div#panel_second_images div.item div.title{text-align:center;}

        </style>
     <?
 }

 function panel_alert_not_valid_img()
 {   ?><div class="alert">Этот файл не является изображением. Распознавание документа невозможно.</div>
     <div class="panel_buttons"><button class="button v2" cmd="esmo_magnit/ScanCaptureError" scan_id="<?echo $this->rec_scan['pkey']?>" url_page="<?echo _CUR_REPORT_DIR?>">Отменить загрузку (скан загружен ошибочно)</button></div><?
     if ($this->rec_scan['status']!=3 and $this->rec_scan['status']!=4)
     { DOCS()->scan_update($this->rec_scan['pkey'],array('doc_id'=>-1,'status'=>5)) ;
     $this->rec_scan['doc_id']=-1 ;
     $this->rec_scan['status']=5 ;
 }
 }

function panel_JS_capture_img()
{  ?><div id="panel_JS_capture_img">
      <div class="info">Ожидайте, идет распознование QR-кода <br><img src="<?echo _PATH_TO_EXT.'/esmo_magnit/img/loading14.gif'?>"></div>
    <script type="text/javascript" src="<?echo _PATH_TO_EXT?>/esmo_magnit/js/llqrcode.js"></script>
      <script type="text/javascript" src="<?echo _PATH_TO_EXT?>/esmo_magnit/js/webqr.js"></script>
      <div id="mainbody" style="display: inline;position:absolute;top:0;left:0;"><canvas id="qr-canvas" width="800" height="600" style="width: 800px; height: 600px;"></canvas></div>
    <? // берем только верхний правый угол, где должен быть QR код
       $img_to_decode=$this->cropImage(_DIR_TO_ROOT.$this->rec_scan['obj_name']) ;


    ?>
         <script type="text/javascript">
             $j(document).ready(function()
             {  load();
                scan_id=<?echo $this->rec_scan['pkey']?> ;
                scan_file="<?echo basename($img_to_decode)?>" ;
                CaptureEndAJAXcmd='esmo_magnit/ScanCaptureEnd' ;
                //qrcode.decode($j('#doc_image').attr('src'));
                qrcode.decode('<?echo $img_to_decode?>');
             }) ;
      </script>
   </div><?
}

 function cropImage($imagePath)
 {   //echo '$imagePath='.$imagePath.'<br>' ;
     $arr_info=getimagesize($imagePath,$arr_info2) ;
     //echo 'Размер изображения: тип файла '.$arr_info['mime'].', разрешение '.$arr_info[0].'x'.$arr_info[1].', размер '.show_size(filesize($imagePath)).'<br>' ;
     $width=$arr_info[0]/3 ;
     $height=$arr_info[1]/4 ;
     $startX=$arr_info[0]-$width ;
     $startY=0;

     $images = new Imagick(realpath($imagePath));
     $images->setResolution(300,300);
     //$images->readImage($saved_file_dir);
     $images->cropImage($width, $height, $startX, $startY);
     //$images->rotateimage('#ffffff', 8);
     $saved_img_file_name='crop_'.basename($imagePath) ;
     $saved_img_file_dir=_TEMP_DIR.'uploads/'.$saved_img_file_name;
     //$koof=Imagick::getQuantum() ;
     $koof=65535 ;
     $images->thresholdImage($GLOBALS['LS_qr_code_scan_threshold'] * $koof);
     //$images->setColorspace(imagick::IMGTYPE_GRAYSCALE);
     //$images->setCompression(Imagick::COMPRESSION_JPEG);
     $images->setCompressionQuality(100);
     $images->setImageFormat("jpg");
     $images->writeImage($saved_img_file_dir);
     //echo '$saved_img_file_name='.$saved_img_file_name.'<br>' ;
     /*if (file_exists($saved_img_file_dir)){?><img src="<? echo _UPLOADS_DIR.$saved_img_file_name?>" style="border:1px solid red;"><?}*/
     return(_UPLOADS_DIR.$saved_img_file_name) ;
    }


function panel_scan_info_view()
{  ?><table class="basic fz_small center full auto" id="panel_scan_info_view">
       <tr><th>Время<br>загрузки</th>
           <th>АТП<br>загрузки</th>
           <th>Источник</th>
           <th>Время<br>ожидания</th>
           <th>Оператор</th>
           <th>Начало<br>обработки</th>
           <th>Время<br>обработки</th>
           <th>Статус</th>
       </tr>
       <tr>
           <td class="center"><?echo date('d.m.Y H:i',$this->rec_scan['c_data'])?><??></td>
           <td class="center"><?
               if ($this->rec_scan['group_upload']) echo $this->rec_scan['_group_upload_name'];
               else
               {  $arr_groups=ACCOUNTS()->get_arr_groups_to_cur_account() ;
                  ?><form><select class=filter name="group_id"><option value="0"></option>
                      <? if (_sizeof($arr_groups)) foreach($arr_groups as $id=>$name){?><option value="<?echo $id?>"><?echo $name?></option><?} ?>
                    </select><br><br><input type="submit" class="button v2" cmd="esmo_magnit/save_scan_group" scan_id="<?echo $this->rec_scan['pkey']?>" value="Сохранить"></form><?

               }

               ?></td>
           <td class="center"><?echo $this->rec_scan['_source']?><??></td>
           <td class="center"><?if ($this->rec_scan['data_work'])  echo ENGINE()->get_text_time_diff($this->rec_scan['c_data'],$this->rec_scan['data_work']) ;?></td>
           <td class="center"><?echo $this->rec_scan['_account_work_name']?></td>
           <td class="center"><?if ($this->rec_scan['data_work']) echo date('d.m.Y H:i',$this->rec_scan['data_work'])?></td>
           <td class="center"><?if ($this->rec_scan['data_set']) echo ENGINE()->get_text_time_diff($this->rec_scan['data_work'],$this->rec_scan['data_set']) ;?></td>
           <td style="font-size:18px;color: <?if ($this->rec_scan['status']==3) echo 'green'; if ($this->rec_scan['status']==4) echo 'red';?>"><?echo $_SESSION['ARR_status_scan'][$this->rec_scan['status']]?></td>
       </tr>
     </table><?

}



function panel_card_personal_view()
 { include_once(_DIR_EXT.'/esmo_magnit/panel_personal_info_small.php') ;
   ?><div id="panel_card_personal_view">
     <?if ($this->rec_personal['pkey']){?>
       <h2>Сотрудник</h2>
       <table class="cols3">
         <tr><td class="img"><img class="shadow main" src="<?echo img_clone($this->rec_personal,'200')?>">
                             <?if (!$this->rec_personal['enabled']){?><div class="personal_fired">Уволен</div><?}?>
             </td>
             <td class="info"><?panel_personal_info_small($this->rec_personal,array()); ?></td>
             <td class="krit"></td>
         </tr>
       </table><?}?>
    </div>
  <?
 }
function panel_card_doc_view()
 { ?><div id="panel_card_personal_view">
     <?if ($this->rec_doc['pkey']){?>
       <h2>Документ</h2>
       <table class="cols2">
         <tr><th>Документ ЭСМО:</th><td><a href="<?echo $this->rec_doc['__href_window']?>" class="new_window" title="window_doc_<?echo $this->rec_doc['pkey']?>"><?echo $this->rec_doc['obj_name']?></a></td></tr>
         <?if ($this->rec_doc['sign_data']){?><tr><th>Дата выдачи:</th><td><?echo date('d.m.Y H:i',$this->rec_doc['sign_data'])?></td></tr><?}?>
         <!--<?if ($this->rec_scan['data_doc']){?><tr><th>Дата подписи:</th><td><?echo date('d.m.Y',$this->rec_scan['data_doc'])?></td></tr><?}?>-->
       </table><br><?}?>
    </div>
  <?
    // damp_array($this->rec_doc) ;
 }

 function panel_card_scan_source_view()
 { ?><div id="panel_card_personal_view">
       <h2>Документ</h2>
       <table class="cols2">
         <?if ($this->rec_scan['report_code'])
         {   $rec_report=REPORTS()->docs_list[$this->rec_scan['report_code']] ;
             ?><tr><th>Тип документа:</th><td><?echo $rec_report['section_title'].' / '.$rec_report['name'] ;?></td></tr><?
         }?>
         <?if ($this->rec_scan['source_obj'])
         {   $rec_event_obj=EVENTS()->get_event_obj_by_ext($this->rec_scan['source_obj']) ;
             $event_obj_name=(is_object($rec_event_obj))? $rec_event_obj->name:$this->rec_scan['source_obj'] ;
             ?><tr><th>Мероприятие документа:</th><td><?echo $event_obj_name?></td></tr><?

         }?>
         <tr><th>Документ ЭСМО:</th><td>не сопоставлен</td></tr>
         <!--<?if ($this->rec_scan['data_doc']){?><tr><th>Дата подписи:</th><td><?echo date('d.m.Y',$this->rec_scan['data_doc'])?></td></tr><?}?>-->
       </table><br>
    </div>
  <?
    // damp_array($this->rec_doc) ;
 }

function panel_cur_group_medic_view()
{ ?><div id="panel_cur_group_medic_view">
    <h2>Текущие группы сотрудника по болезни</h2><?
    if (_sizeof($this->rec_personal['_groups_medic'])){?><div id=personal_groups style="font-size:18px;color:red;"><? if (_sizeof($this->rec_personal['_groups_medic'])) echo implode(', ',$this->rec_personal['_groups_medic']) ?></div><?}
    else echo 'не задано' ;
  ?></div><?
}



  // в дальнейшем вынести эту функцию в собственный класс мероприятия
  function panel_view_diagnoz()
  { ?><div id="panel_view_diagnoz" style="margin-bottom:20px;">
      <h2><?echo ($this->rec_scan['diagnoz'] and $this->rec_scan['status']==2)? 'Старый диагноз':'Диагноз'?></h2>
      <div style="border:1px solid #eeeeee;padding:20px;text-align:center;background:#9bdadd;font-size:16px;"><?echo $this->rec_scan['diagnoz']?></div>
      <?if ($this->rec_scan['comment']){?><strong>Комментарий к диагнозу:</strong><div class="comment"><?echo $this->rec_scan['comment']?></div><?}?>
      <?if ($this->rec_scan['data_doc']){?><div style="margin:10px 0;">Дата заключения: <span style="font-size:18px;"><?echo date('d.m.Y',$this->rec_scan['data_doc'])?></span></div><?}?>
    </div><?
  }

  function panel_change_diagnoz_button()
  {  ?><div id="panel_filter">
                  <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir">
                       <div id="panel_buttons">
                          <button class="button v2" cmd="esmo_magnit/diagnoz_change"  scan_id="<?echo $this->rec_scan['pkey']?>">Изменить диагноз</button>&nbsp;&nbsp;
                      </div>
                   </form>
        </div>
     <?
  }


  function panel_scan_capture_repeat()
  {  ?><div id="panel_filter">
                  <form id="sky-form" class="sky-form">
                       <div id="panel_buttons">
                          <button class="button v2" cmd="esmo_magnit/ScanCaptureRepeat"  scan_id="<?echo $this->rec_scan['pkey']?>" url_page="<?echo _CUR_REPORT_DIR?>">Повторно распознать документ</button>&nbsp;&nbsp;
                          <button class="button v2" cmd="esmo_magnit/ScanCaptureError"  scan_id="<?echo $this->rec_scan['pkey']?>" url_page="<?echo _CUR_REPORT_DIR?>">Документ загружен ошибочно</button>&nbsp;&nbsp;
                      </div>
                   </form>
        </div>
     <?
  }

 function panel_search_personals()
 {
     ?><div id="panel_search_personals"><h2>Поиск сотрудника</h2>
     <div id="panel_filter">
              <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                   <fieldset>
                        <div class="row">
                           <section class="col col-11">
                                <label class="label">ФИО</label>
                                <label class="input">
                                     <input type="text" name="filter[name]" placeholder="" SetAutoComplete data-required cmd="autocomplette_personal_name" value="<?echo $this->filter['name']?>">
                                </label>
                           </section>
                        </div>
                        <?
                        $scan_priority=SETUP()->load_ini_setting('/ini/scan_priority.yaml') ;
                        ?>
                        <div class="row">
                           <section  class="col col-4">
                                <label class="label">Тип документа</label>
                                <label class="select">
                                    <select name="filter[doc_type]"><option value="0"></option>
                                        <?/* if (_sizeof(ENGINE()->docs_list)) foreach(ENGINE()->docs_list as $doc_code=>$doc_rec) {?><option value="<?echo $doc_code?>" <?if ($doc_code==$this->filter['doc_type']) echo 'selected'?>><?echo $doc_rec['name']?></option><?}*/?>
                                        <optgroup label="Основные типы документов/сканов">
                                        <? if (_sizeof(REPORTS()->docs_list)) foreach(REPORTS()->docs_list as $doc_code=>$rec) if ($scan_priority[$doc_code]) {?><option value="<?echo $doc_code?>" <?if ($doc_code==$this->filter['doc_type']) echo 'selected'?>><?echo $rec['section_title'].' / '.$rec['name']?></option><?}?>
                                        </optgroup>
                                        <optgroup label="Дополнительные типы документов/сканов">
                                        <? if (_sizeof(REPORTS()->docs_list)) foreach(REPORTS()->docs_list as $doc_code=>$rec) if (!$scan_priority[$doc_code]){?><option value="<?echo $doc_code?>" <?if ($doc_code==$this->filter['doc_type']) echo 'selected'?>><?echo $rec['section_title'].' / '.$rec['name']?></option><?}?>
                                        </optgroup>
                                        <!--<option value="napravlenie" <?if ($this->filter['doc_type']=='napravlenie') echo 'selected'?>>Направление по АГ</option>
                                        <option value="doc|esmo_magnit_pmo|zakluchenie" <?if ($this->filter['doc_type']=='doc|esmo_magnit_pmo|zakluchenie') echo 'selected'?>>Заключение ПМО</option>
                                        <option value="doc|events_opo|zakluchenie_opo" <?if ($this->filter['doc_type']=='doc|events_opo|zakluchenie_opo') echo 'selected'?>>Заключение ОПО</option>
                                        -->
                                    </select>
                                </label>
                           </section>
                           <section class="col col-2">
                                <label class="label">Номер</label>
                                <label class="input"><input type="text" name="filter[doc_number]" value="<?echo $this->filter['doc_number']?>"></label>
                           </section>
                        </div>
                   </fieldset>
                  <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Найти" validate="form"></div>
               </form>
        </div></div>
      <?

     $cnt=-1 ;
     if ($this->filter['name'] and $this->filter['doc_type'])
     {   ?><form class="sky-form no_box_shadow"><?
          include_once(_DIR_EXT.'/docs/report_docs.php') ;
          $report_obj=new report_docs() ;
          $report_obj->no_view_title=1;
          $report_obj->filter['order']='c_data desc';
          ob_start() ;
          $cnt=$report_obj->view_as_HTML(array('check_type'=>'radio','template_name'=>'template_HTML_check')) ;
          $text=ob_get_clean() ;
          if ($cnt){echo $text ; ?><br><div id="panel_buttons"><button class="button v2" cmd="esmo_magnit/set_doc_to_scan" url_page="<?echo _CUR_REPORT_DIR?>" scan_id="<?echo $this->rec_scan['pkey']?>">Выбрать отмеченный документ</button></div><?}
          else echo '<div class="alert" style="text-align:center;">Документ не найден, будет выполнен поиск по фамилии</div>' ;
          ?></form><br><br><br><?
     }
     if ($this->filter['name'] and (!$this->filter['doc_type'] and !$this->filter['doc_number'] or !$cnt))
      {   ?><form class="sky-form no_box_shadow"><?
          include_once(_DIR_EXT.'/esmo_setting/report_personals_to_group.php') ;
          $report_obj=new report_personals_to_group() ;
          $report_obj->no_view_title=1;
          $report_obj->filter['order']='obj_name';
          $cnt=$report_obj->view_as_HTML(array('check_type'=>'radio','template_name'=>'print_template_HTML_small')) ;
          if ($cnt){?><br><div id="panel_buttons"><button class="button v2" cmd="esmo_magnit/set_personal_to_scan" url_page="<?echo _CUR_REPORT_DIR?>" scan_id="<?echo $this->rec_scan['pkey']?>">Выбрать отмеченного сотрудника</button></div><?}
          ?></form><br><br><br><?
      }


 }

 function panel_other_docs()
 {//damp_array(REPORTS()->docs_list);
   $scan_priority=SETUP()->load_ini_setting('/ini/scan_priority.yaml') ;
     ?><div id="panel_search_personals">
     <div id="panel_filter">
              <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                   <fieldset>
                        <div class="row">
                           <section  class="col col-8">
                                <label class="label">Тип документа</label>
                                <label class="select">
                                    <select name="filter[report_code]"><option value="0"></option>
                                        <optgroup label="Основные типы документов/сканов">
                                        <? if (_sizeof(REPORTS()->docs_list)) foreach(REPORTS()->docs_list as $doc_code=>$rec) if ($scan_priority[$doc_code]) {?><option value="<?echo $doc_code?>" <?if ($doc_code==$this->filter['report_code']) echo 'selected'?>><?echo $rec['section_title'].' / '.$rec['name']?></option><?}?>
                                        </optgroup>
                                        <optgroup label="Дополнительные типы документов/сканов">
                                        <? if (_sizeof(REPORTS()->docs_list)) foreach(REPORTS()->docs_list as $doc_code=>$rec) if (!$scan_priority[$doc_code]){?><option value="<?echo $doc_code?>" <?if ($doc_code==$this->filter['report_code']) echo 'selected'?>><?echo $rec['section_title'].' / '.$rec['name']?></option><?}?>
                                        </optgroup>
                                    </select>
                                    <input type="submit" class="button v2" cmd="esmo_magnit/set_report_code_to_scan"  url_page="<?echo _CUR_REPORT_DIR?>" scan_id="<?echo $this->rec_scan['pkey']?>" value="Задать тип документа" validate="form">
                                </label>

                           </section>
                        </div>
                   </fieldset>
                  <div id="panel_buttons"></div>
               </form>
        </div></div>
      <?
 }

 function panel_scan_debug_info()
 {  $arr['pkey']=$this->rec_scan['pkey'] ;
    $arr['status']=$this->rec_scan['status'] ;
    $arr['member_id']=$this->rec_scan['member_id'] ;
    $arr['doc_id']=$this->rec_scan['doc_id'] ;
    $arr['personal_id']=$this->rec_scan['personal_id'] ;
    $arr['diagnoz']=$this->rec_scan['diagnoz'] ;
    $arr['comment']=$this->rec_scan['comment'] ;
    $arr['source']=$this->rec_scan['source'] ;
    $arr['account_upload']=$this->rec_scan['account_upload'] ;
    $arr['data_work']=date('d.m.y H:i:s',$this->rec_scan['data_work']) ;
    $arr['data_set']=date('d.m.y H:i:s',$this->rec_scan['data_set']) ;
    $res[]=$arr ;
    ?><br><br><br><br><?
    print_2x_arr($res) ;

 }


}



?>
