<?
class report_pp_result2 extends c_report
{
    var $title='Результаты пупиллометрии' ;
    var $view_by_space_filter=1;


    function setting()
    {
        ?><div id="panel_filter">
        <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="/cab/personal/person/<?echo _CUR_ID?>/pp/">
            <fieldset>
                <div class="row">
                    <section class="col col-3">
                        <label class="label">Результаты пупиллометрии:</label>
                        <label class="select">
                            <select name="filter[pp_result]">
                                <option value="0"></option>
                                <?
                                $pp_result_list=PP()->getPPResultList();
                                if (_sizeof($pp_result_list)) foreach($pp_result_list as $key=>$rec) {?><option value="<?echo $key?>" <?if ($this->filter['pp_result']==$key) echo 'selected'?>><?echo $rec?></option><?}?>
                            </select>
                        </label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Время измерения от:</label>
                        <label class="input"><input type="text" name="filter[timepick_from]" class="timepicker_test" value="<?echo $this->filter['timepick_from']?>"></label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Время измерения до:</label>
                        <label class="input"><input type="text" name="filter[timepick_to]" class="timepicker_test"  value="<?echo $this->filter['timepick_to']?>"></label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Дата измерения от:</label>
                        <label class="input"><input type="text" name="filter[data_from]" class="datepicker" value="<?echo $this->filter['data_from']?>"></label>
                    </section>
                    <section class="col col-2">
                        <label class="label">Дата измерения до:</label>
                        <label class="input"><input type="text" name="filter[data_to]" class="datepicker" value="<?echo $this->filter['data_to']?>"></label>
                    </section>
                </div>
                <div class="row">
                    <section class="col col-3">
                        <label class="checkbox"><input type="checkbox" name="filter[no_approximate]" value="1" <?if ($this->filter['no_approximate']) echo 'checked'?>><i></i>Отображать исходный график</label>
                    </section>
                    <section class="col col-3">
                        <label class="checkbox"><input type="checkbox" name="filter[view_old_result]" value="1" <?if ($this->filter['view_old_result']) echo 'checked'?>><i></i>Отображать неучитываемые результаты</label>
                    </section>
                </div>
            </fieldset>
            <?$this->panel_button_apply();?>
        </form>
        </div><br>
        <script type="text/javascript">
            $j('.timepicker_test').timepicker();
        </script>
        <?
    }

    function create_usl_select_obj($_params,&$options)
    {
        $usl=array() ;
        $usl[]='id_mo>0';
//        $this->filter['personal_id']=10380;

        if ($this->filter['personal_id']) $usl[]='personal_id='.$this->filter['personal_id'];

        if ($this->filter['pp_result']) $usl[]='result_code='.$this->filter['pp_result'];

        if ($this->filter['timepick_from'] and $this->filter['timepick_to']){ //условие по времени результата ПП
            $usl[]=PP()->getTimepickQuery(0,$this->filter['timepick_from'],$this->filter['timepick_to']);
        } elseif ($this->filter['timepick_from'])  {
            $usl[]=PP()->getTimepickQuery(1,$this->filter['timepick_from']);
        } elseif ($this->filter['timepick_to']) {
            $usl[]=PP()->getTimepickQuery(2,$this->filter['timepick_to']);
        }

        if ($this->filter['data_from']) $usl[]='c_data>='.strtotime($this->filter['data_from']);
        if ($this->filter['data_to']) $usl[]='c_data<='.strtotime($this->filter['data_to']);

        if ($this->filter['name'])              $usl[]='t2.obj_name like "'.$this->filter['name'].'%"' ;

        if (!$this->filter['view_old_result']) $usl[]='enabled=1';

        $usl_res=implode(' and ',$usl) ;

        return($usl_res) ;
    }

    function get_cnt_items($usl,$options=array())
    {
//        $options['debug']=1;
        $cnt = execSQL_value('select count(pkey) from obj_site_narko_data where '.$usl,$options);
        return $cnt;
    }

    function get_items($usl,$options=array())
    {
//        $options['debug']=1;
        $limit=($options['limit'])? ' '.$options['limit']:'' ;
        $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by pkey desc' ;
        $list_rec=execSQL('select * from obj_site_narko_data where '.$usl.$order.$limit,$options);

        return($list_rec) ;
    }

    function print_template_HTML($list_recs,$options=array())
    {

        $rec_norm=execSQL_van("select * from obj_site_narko_data_out_303 where user_id=".$this->filter['personal_id']);
        ?>
        <form>
            <div id="panel_list_rec_popilumetr">
                <table>
                    <tr>
                        <th>№</th>
                        <th>Выбор<br>график</th>
                        <th>Выбор<br>норма</th>
                        <th>ID записи</th>
                        <th>Дата медосмотра</th>
                        <th>ID медосмотра</th>
                        <th>Lux</th>
                        <th>Латентное время<br>на включение<br>светодиода</th>
                        <th>Дн(мм)</th>
                        <th>Тл(с)</th>
                        <th>Комментарий</th>
                        <th>Результат</th>
                    </tr>
                <?
                $i=$this->first_obj ;
                if (_sizeof($list_recs)) foreach($list_recs as $rec)
                {
                    $result = PP()->check_narko_by_data($rec, $rec_norm);
                    $analyzer = PP()->getAnalyzerByNarko($rec);

                    $TlatFirst=$analyzer->getTlatFirst();
                    ?>
                    <tr class=item>
                        <td><?echo $i; $i++;?></td>
                        <td><?if ($rec['enabled']) {?><input type="checkbox" value="<?echo $rec['pkey'];?>" name="check_popolom_id[]"><?}?></td>
                        <td><?if ($rec['enabled']) {?><input type="radio" value="<?echo $rec['pkey'];?>"<?if ($rec_norm['pp_id'] == $rec['pkey']) echo " checked";?> name="use_pp_norma"><?}?></td>
                        <td class="preview_graf"><div><?echo $rec['pkey'];?><div class="panel_PP_preview" pp_id="<?echo $rec['pkey']?>" no_approximate="<?echo ($this->filter['no_approximate'])? 1:0?>" id="panel_PP_preview_<?echo $rec['pkey']?>"></div></div></td>
                        <td><?echo date('d.m.Y H:i:s',$rec['c_data'])?></td>
                        <td><?echo $rec['id_mo'];?></td>
                        <td><?echo $rec['lux']*$GLOBALS['LS_pp_lux_koof'];?></td>
                        <td><?echo $TlatFirst?></td>
                        <td><textarea class="v2" style="width:70px; height:20px;" cmd="aspmo_pp/save_dn_result" event="change" no_send_form="1" pp_id="<?echo $rec['pkey']?>"><?echo $rec['dn_result']?></textarea></td>
                        <td><textarea class="v2" style="width:70px; height:20px; cmd="aspmo_pp/save_tl_result" event="change" no_send_form="1" pp_id="<?echo $rec['pkey']?>"><?echo $rec['tl_result']?></textarea></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/person/<? echo $rec['pkey']?>/" class="new_window"><?echo ($result[0])? $result[0]:'норма';?></a></td>
                    </tr>
                    <?
                }
                ?>
                </table>
            </div>
            <div class="buttons">
                <button class="v2" cmd=aspmo_pp/calculate_norm_auto personal_id="<?echo $this->filter['personal_id']?>">Посчитать норму автоматически</button>
                <button class="v2" cmd=aspmo_pp/calculate_norm personal_id="<?echo $this->filter['personal_id']?>">Посчитать норму</button>
                <button class="v2" cmd=aspmo_pp/delete_norm personal_id="<?echo $this->filter['personal_id']?>">Удалить норму</button>
                <button class="v2" cmd=aspmo_pp/delete>Удалить</button>
            </div>
        </form>
        <?
    }


}

?>
