<?
function panel_pp_journal($options=array())
{   $_usl=array() ;
    $_usl[]='clss=300' ;
    if ($options['terminal_id']) $_usl[]='terminal_id='.$options['terminal_id'] ;
    if ($options['time_from']) $_usl[]='c_data>='.strtotime($options['time_from']) ;
    if ($options['time_to']) $_usl[]='c_data<='.strtotime($options['time_to'].' 23:59:59') ;
    if ($options['text_info'])
         {   $arr_ids=execSQL_line('select pkey from obj_site_personals where clss=211 and obj_name like "%'.addslashes($options['text_info']).'%" or propusk like "'.addslashes($options['text_info']).'" or driving like "'.addslashes($options['text_info']).'" or tab_number like "'.addslashes($options['text_info']).'"') ;
             if (_sizeof($arr_ids))  $_usl[]='personal_id in ('.implode(',',$arr_ids).')' ;
             else                   $_usl[]='personal_id=0' ;
         }
    $usl=implode(' and ',$_usl) ;
    $recs=execSQL('select * from obj_site_narko_data where '.$usl.' order by c_data desc') ;
    $stats=execSQL_van('select min(c_data) as time_from,max(c_data) as time_to,count(pkey) as cnt from obj_site_narko_data where '.$usl)  ;
    echo 'Найдено <strong>'.$stats['cnt'].'</strong> измерений' ;
    if ($options['time_from'])  echo ' c <strong>'.$options['time_from'].'</strong>' ;
    if ($options['time_to'])  echo ' по <strong>'.$options['time_to'].'</strong>' ;
     echo '<br>' ;

    ?><div id="panel_list_rec_popilumetr">
         <table><tr><th>Выбор</th><th>ID записи</th><th>Терминал</th><th>Сотрудник</th><th>Возраст</th><th>Пол</th><th>Кол-во<br>измерений</th><th>Норма</th><th>Комментарий</th><th>Результат</th></tr>
             <? foreach ($recs as $rec)
             { list($result,$code)=PP()->check_narko($rec['pkey']) ;
               $result_text=(!$result)? 'норма':$result ;
               if (!$options['result'] or ($options['result'] and strpos($result_text,$options['result'])!==false))
               {   $rec_personal=PERSONAL()->get_personal_by_id($rec['personal_id']) ;
                   $rec_norm=execSQL_van('select * from obj_site_narko_data_out_303 where user_id='.$rec['personal_id']) ;
                   $cnt=execSQL_value('select count(pkey) from obj_site_narko_data where personal_id='.$rec['personal_id']) ;
                   ?><tr id="tr_<?echo $rec['pkey']?>">
                     <td><input type="checkbox" value="<?echo $rec['pkey'];?>" name="check_popolom_id[]" class="v2" cmd=aspmo_pp/draw></td>
                     <td class="preview_graf"><div><?echo $rec['pkey'];?><div class="panel_PP_preview" pp_id="<?echo $rec['pkey']?>" id="panel_PP_preview_<?echo $rec['pkey']?>"></div></div></td>
                     <td><?echo $rec['terminal_id']?></td>
                     <td><a href="/cab/personal/person/<?echo $rec['personal_id']?>/pp/" class="new_window"><?echo $rec_personal['obj_name'];?></a></td>
                     <td><?echo $rec_personal['age']?></td>
                     <td><?echo $rec_personal['_pol'];?></td>
                     <td><?echo $cnt;?></td>
                     <td><?if($rec_norm['pkey']){?><div class="green">ДА</div><?}?></td>
                     <td><textarea class="v2" cmd="aspmo_pp/save_comment" event="change" no_send_form="1" pp_id="<?echo $rec['pkey']?>"><?echo $rec['comment']?></textarea></td>
                     <td class="result <?echo ($result!="")? 'error':'ok';?>"><a href="/cab/pp/<? echo $rec['pkey']?>/" class="new_window"><?echo $result_text?></a></td>
                 </tr><?
              }
            }
         ?></table></div>
<script type="text/javascript">
    $j(document).ready(function()
    { $j('#panel_list_rec_popilumetr input[type="checkbox"]').click(function() { $j(this).closest('tr').toggleClass('selected') ;});
      $j('td.preview_graf').hover(preview_graf_on,preview_graf_off) ;
    }) ;

    function preview_graf_on()
    { $j(this).find('div.panel_PP_preview').show() ;
      if ($j(this).find('div.panel_PP_preview').html()=="")
      { var pp_id=$j(this).find('div.panel_PP_preview').attr('pp_id') ;
        send_ajax_request({cmd:'aspmo_pp/draw_preview',pp_id:pp_id}) ;
      }
    }
    function preview_graf_off()
    {
     $j(this).find('div.panel_PP_preview').hide() ;
    }
</script>

<?
}


?>
