<?php
class report_log_signatures extends c_report
{
    var $title='Журнал подписей' ;
    var $allow_to_rol=array() ;
    var $filter=array() ;
    var $view_by_space_filter=1 ;
    var $use_jwplayer=1 ;

    function get_terminals() {
        return execSQL_row("SELECT DISTINCT(`sms`.`terminal_id`) AS `term_id`, `sa`.`obj_name` FROM `obj_site_mo_session` AS `sms`"
                            . " INNER JOIN `obj_site_mo_session_DTW` AS `sms_DTW` ON `sms_DTW`.`parent` = `sms`.`pkey`"
                            . " LEFT JOIN `obj_site_account` AS `sa` ON `sa`.`id` = `sms`.`terminal_id` AND `sa`.`clss` = 203"
                            . " WHERE `sms`.`terminal_id` > 0");
    }

    function setting($options=array())
    {   ?><div id="panel_filter" class="one_row">
                <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                     <fieldset>
                         <div class="row" id="person_info">
                            <section class="col col-2">
                                 <label class="label">Сотрудник</label>
                                 <label class="input">
                                     <input type="text" name="filter[personal_name]"  SetAutoComplete cmd="autocomplette_personal_name" value="<?if ($this->filter['personal_name']) echo $this->filter['personal_name']?>">
                                 </label>
                            </section>
                             <section class="col col-2">
                                  <label class="label">Терминал</label>
                                  <label class="select">
                                    <select name="filter[terminal]" id="terminal">
                                        <option value="0">Все</option>
                                        <? $terminals = $this->get_terminals();
                                        if (_sizeof($terminals)) foreach($terminals as $id => $name){?><option value="<?echo $id?>" <?if ($this->filter['terminal']==$id) echo 'selected'?>><?echo ($name)? $name:'#'.$id?></option><?}?>
                                    </select>
                                  </label>
                               </section>
                             <section class="col col-2">
                                 <label class="label">Дата от</label>
                                 <label class="input">
                                     <i class="icon-append fa fa-calendar"></i>
                                     <input type="text" name="filter[data_from]" class="datetimepicker" value="<?if ($this->filter['data_from']) echo $this->filter['data_from']?>">
                                 </label>
                               </section>
                               <section class="col col-2">
                                 <label class="label">Дата до</label>
                                 <label class="input">
                                     <i class="icon-append fa fa-calendar"></i>
                                     <input type="text" name="filter[data_to]" class="datetimepicker" value="<?if ($this->filter['data_to']) echo $this->filter['data_to']?>">
                                 </label>
                            </section>
                            <!--section class="col col-2">
                                 <label class="label">Кол-во точек от</label>
                                 <label class="input">
                                     <input type="text" name="filter[point_count_from]" value="<?if (is_numeric($this->filter['point_count_from'])) echo $this->filter['point_count_from']?>">
                                 </label>
                            </section>
                            <section class="col col-2">
                                 <label class="label">Кол-во точек до</label>
                                 <label class="input">
                                     <input type="text" name="filter[point_count_to]" value="<?if (is_numeric($this->filter['point_count_to'])) echo $this->filter['point_count_to']?>">
                                 </label>
                             </section>
                            <section class="col col-2">
                                 <label class="label">Продолжительность подписи от</label>
                                 <label class="input">
                                     <input type="text" name="filter[time_sign_from]" value="<?if (is_numeric($this->filter['time_sign_from'])) echo $this->filter['time_sign_from']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Продолжительность подписи до</label>
                                 <label class="input">
                                     <input type="text" name="filter[time_sign_to]" value="<?if (is_numeric($this->filter['time_sign_to'])) echo $this->filter['time_sign_to']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Количество точек в секунду от</label>
                                 <label class="input">
                                     <input type="text" name="filter[point_per_sec_from]" value="<?if (is_numeric($this->filter['point_per_sec_from'])) echo $this->filter['point_per_sec_from']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Количество точек в секунду до</label>
                                 <label class="input">
                                     <input type="text" name="filter[point_per_sec_to]" value="<?if (is_numeric($this->filter['point_per_sec_to'])) echo $this->filter['point_per_sec_to']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Отклонение по форме от</label>
                                 <label class="input">
                                     <input type="text" name="filter[DTW_from]" value="<?if (is_numeric($this->filter['DTW_from'])) echo $this->filter['DTW_from']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Отклонение по форме до</label>
                                 <label class="input">
                                     <input type="text" name="filter[DTW_to]" value="<?if (is_numeric($this->filter['DTW_to'])) echo $this->filter['DTW_to']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Отклонение по времени от</label>
                                 <label class="input">
                                     <input type="text" name="filter[time_deviation_from]" value="<?if (is_numeric($this->filter['time_deviation_from'])) echo $this->filter['time_deviation_from']?>">
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Отклонение по времени до</label>
                                 <label class="input">
                                     <input type="text" name="filter[time_deviation_to]" value="<?if (is_numeric($this->filter['time_deviation_to'])) echo $this->filter['time_deviation_to']?>">
                                 </label>
                             </section>
                            <section class="col col-2">
                                <label class="label">Сортировка по</label>
                                <label class="select">
                                    <select name="filter[orderby]" id="orderby">
                                        <option value="date" <?if ($this->filter['orderby']=='date') echo 'selected'?>>Дате</option>
                                        <option value="name" <?if ($this->filter['orderby']=='name') echo 'selected'?>>Имени</option>
                                        <option value="age" <?if ($this->filter['orderby']=='age') echo 'selected'?>>Возрасту</option>
                                        <option value="point_count" <?if ($this->filter['orderby']=='point_count') echo 'selected'?>>Количеству точек</option>
                                        <option value="time_sign" <?if ($this->filter['orderby']=='time_sign') echo 'selected'?>>Продолжительности подписи</option>
                                        <option value="point_per_sec" <?if ($this->filter['orderby']=='point_per_sec') echo 'selected'?>>Количеству точек в секунду</option>
                                        <option value="cost" <?if ($this->filter['orderby']=='cost') echo 'selected'?>>Отклонению по форме</option>
                                        <option value="time_deviationn" <?if ($this->filter['orderby']=='time_deviation') echo 'selected'?>>Отклонению по времени</option>
                                        <option value="standart" <?if ($this->filter['orderby']=='standart') echo 'selected'?>>Эталону</option>
                                        <option value="result" <?if ($this->filter['orderby']=='result') echo 'selected'?>>Результату</option>
                                        <option value="pkey" <?if ($this->filter['orderby']=='pkey') echo 'selected'?>>Идентификатору</option>
                                    </select>
                                </label>
                            </section>
                            <section class="col col-2">
                                  <label class="label">Сортировка</label>
                                  <label class="select">
                                     <select name="filter[order]" id="order">
                                         <option value="0" <?if (!$this->filter['order']) echo 'selected'?>>Обратная</option>
                                         <option value="1" <?if ($this->filter['order']==1) echo 'selected'?>>Прямая</option>
                                     </select>
                                  </label>
                            </section>
                           </div>
                         <div class="row">
                            <section class="col col-2">
                                <label class="label">Эталонная подпись</label>
                                <label class="radio"><input type="radio" name="filter[has_standart]" value="" <?if ($this->filter['has_standart']=="") echo 'checked=checked'?>><i></i>Все</label>
                                <label class="radio"><input type="radio" name="filter[has_standart]" value="1" <?if ($this->filter['has_standart']==1) echo 'checked=checked'?>><i></i>Есть</label>
                                <label class="radio"><input type="radio" name="filter[has_standart]" value="-1" <?if ($this->filter['has_standart']==-1) echo 'checked=checked'?>><i></i>Нет</label>
                            </section>
                            <section class="col col-2">
                                <label class="label">Результат</label>
                                <label class="radio"><input type="radio" name="filter[valid]" value="" checked="" <?if ($this->filter['valid']=="") echo 'checked=checked'?>><i></i>Все</label>
                                <label class="radio"><input type="radio" name="filter[valid]" value="1" <?if ($this->filter['valid']==1) echo 'checked=checked'?>><i></i>Верна</label>
                                <label class="radio"><input type="radio" name="filter[valid]" value="-1" <?if ($this->filter['valid']==-1) echo 'checked=checked'?>><i></i>Не верна</label>
                            </section-->
                         </div>
                     </fieldset>
                    <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="OK"></div>
                 </form>
          </div>
        <?
    }

    function setting_details($options=array())
    {   ?><div id="panel_filter">
                <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                  <fieldset>
                    <section>
                        <label class="label">Сотрудник</label>
                        <label class="input">
                            <input type="text" name="filter[personal_name]"  SetAutoComplete cmd="autocomplette_personal_name" value="<?if ($this->filter['personal_name']) echo $this->filter['personal_name']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Терминал</label>
                        <label class="select">
                            <select name="filter[terminal]" id="terminal">
                                <option value="0">Все</option>
                                <? $terminals = $this->get_terminals();
                                if (_sizeof($terminals)) foreach($terminals as $id => $name){?><option value="<?echo $id?>" <?if ($this->filter['terminal']==$id) echo 'selected'?>><?echo ($name)? $name:'#'.$id?></option><?}?>
                            </select>
                        </label>
                    </section>
                    <section>
                      <label class="label">Дата от</label>
                      <label class="input">
                          <i class="icon-append fa fa-calendar"></i>
                          <input type="text" name="filter[data_from]" class="datetimepicker" value="<?if ($this->filter['data_from']) echo $this->filter['data_from']?>">
                      </label>
                    </section>
                    <section>
                      <label class="label">Дата до</label>
                      <label class="input">
                          <i class="icon-append fa fa-calendar"></i>
                          <input type="text" name="filter[data_to]" class="datetimepicker" value="<?if ($this->filter['data_to']) echo $this->filter['data_to']?>">
                      </label>
                   </section>
                   <section>
                        <label class="label">Кол-во точек от</label>
                        <label class="input">
                            <input type="text" name="filter[point_count_from]" value="<?if (is_numeric($this->filter['point_count_from'])) echo $this->filter['point_count_from']?>">
                        </label>
                   </section>
                   <section>
                        <label class="label">Кол-во точек до</label>
                        <label class="input">
                            <input type="text" name="filter[point_count_to]" value="<?if (is_numeric($this->filter['point_count_to'])) echo $this->filter['point_count_to']?>">
                        </label>
                    </section>
                   <section>
                        <label class="label">Продолжительность подписи от</label>
                        <label class="input">
                            <input type="text" name="filter[time_sign_from]" value="<?if (is_numeric($this->filter['time_sign_from'])) echo $this->filter['time_sign_from']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Продолжительность подписи до</label>
                        <label class="input">
                            <input type="text" name="filter[time_sign_to]" value="<?if (is_numeric($this->filter['time_sign_to'])) echo $this->filter['time_sign_to']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Количество точек в секунду от</label>
                        <label class="input">
                            <input type="text" name="filter[point_per_sec_from]" value="<?if (is_numeric($this->filter['point_per_sec_from'])) echo $this->filter['point_per_sec_from']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Количество точек в секунду до</label>
                        <label class="input">
                            <input type="text" name="filter[point_per_sec_to]" value="<?if (is_numeric($this->filter['point_per_sec_to'])) echo $this->filter['point_per_sec_to']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Отклонение по форме от</label>
                        <label class="input">
                            <input type="text" name="filter[DTW_from]" value="<?if (is_numeric($this->filter['DTW_from'])) echo $this->filter['DTW_from']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Отклонение по форме до</label>
                        <label class="input">
                            <input type="text" name="filter[DTW_to]" value="<?if (is_numeric($this->filter['DTW_to'])) echo $this->filter['DTW_to']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Отклонение по времени от</label>
                        <label class="input">
                            <input type="text" name="filter[time_deviation_from]" value="<?if (is_numeric($this->filter['time_deviation_from'])) echo $this->filter['time_deviation_from']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Отклонение по времени до</label>
                        <label class="input">
                            <input type="text" name="filter[time_deviation_to]" value="<?if (is_numeric($this->filter['time_deviation_to'])) echo $this->filter['time_deviation_to']?>">
                        </label>
                    </section>
                    <section>
                        <label class="label">Эталонная подпись</label>
                        <label class="radio"><input type="radio" name="filter[has_standart]" value="" <?if ($this->filter['has_standart']=="") echo 'checked=checked'?>><i></i>Все</label>
                        <label class="radio"><input type="radio" name="filter[has_standart]" value="1" <?if ($this->filter['has_standart']==1) echo 'checked=checked'?>><i></i>Есть</label>
                        <label class="radio"><input type="radio" name="filter[has_standart]" value="-1" <?if ($this->filter['has_standart']==-1) echo 'checked=checked'?>><i></i>Нет</label>
                    </section>
                    <section>
                        <label class="label">Результат</label>
                        <label class="radio"><input type="radio" name="filter[valid]" value="" checked="" <?if ($this->filter['valid']=="") echo 'checked=checked'?>><i></i>Все</label>
                        <label class="radio"><input type="radio" name="filter[valid]" value="1" <?if ($this->filter['valid']==1) echo 'checked=checked'?>><i></i>Верна</label>
                        <label class="radio"><input type="radio" name="filter[valid]" value="-1" <?if ($this->filter['valid']==-1) echo 'checked=checked'?>><i></i>Не верна</label>
                    </section>
                   <section>
                       <label class="label">Сортировка по</label>
                       <label class="select">
                           <select name="filter[orderby]" id="orderby">
                               <option value="date" <?if ($this->filter['orderby']=='date') echo 'selected'?>>Дате</option>
                               <option value="name" <?if ($this->filter['orderby']=='name') echo 'selected'?>>Имени</option>
                               <option value="age" <?if ($this->filter['orderby']=='age') echo 'selected'?>>Возрасту</option>
                               <option value="point_count" <?if ($this->filter['orderby']=='point_count') echo 'selected'?>>Количеству точек</option>
                               <option value="time_sign" <?if ($this->filter['orderby']=='time_sign') echo 'selected'?>>Продолжительности подписи</option>
                               <option value="point_per_sec" <?if ($this->filter['orderby']=='point_per_sec') echo 'selected'?>>Количеству точек в секунду</option>
                               <option value="cost" <?if ($this->filter['orderby']=='cost') echo 'selected'?>>Отклонению по форме</option>
                               <option value="time_deviationn" <?if ($this->filter['orderby']=='time_deviation') echo 'selected'?>>Отклонению по времени</option>
                               <option value="standart" <?if ($this->filter['orderby']=='standart') echo 'selected'?>>Эталону</option>
                               <option value="result" <?if ($this->filter['orderby']=='result') echo 'selected'?>>Результату</option>
                               <option value="pkey" <?if ($this->filter['orderby']=='pkey') echo 'selected'?>>Идентификатору</option>
                           </select>
                       </label>
                   </section>
                   <section>
                         <label class="label">Сортировка</label>
                         <label class="select">
                            <select name="filter[order]" id="order">
                                <option value="0" <?if (!$this->filter['order']) echo 'selected'?>>Обратная</option>
                                <option value="1" <?if ($this->filter['order']==1) echo 'selected'?>>Прямая</option>
                            </select>
                         </label>
                   </section>
                     </fieldset>
                     <?$this->panel_button_apply();?>
                    <?$this->panel_buttons_action();?>
                    <div id="panel_buttons">
                        <button class="button v2" title="Вспомогательная кнопка, после объединения версий - убрать." cmd="aspmo_sv/sv_calculate_number_of_points">Пересчитать количество точек</button>
                    </div>
                 </form>
          </div><br>
        <?
    }

    function create_usl_select_obj($_params, &$options)
    {
        $where=array() ;
        $where[] = 1;

        if (intval($this->filter['terminal']) > 0) {
            $where[] = 'mos.terminal_id = ' . intval($this->filter['terminal']);
        }

        if ($this->filter['data_from']) {
            $where[] = 'mos.c_data >= ' . strtotime($this->filter['data_from']);
        }

        if ($this->filter['data_to']) {

            $where[] = 'mos.c_data <= ' . strtotime($this->filter['data_to']);
        }

        if (is_numeric($this->filter['point_count_from'])) {
            $where[] = 'mosDTW.point_count >=' . intval($this->filter['point_count_from']);
        }

        if (is_numeric($this->filter['point_count_to'])) {
            $where[] = 'mosDTW.point_count <=' . intval($this->filter['point_count_to']);
        }

        if (is_numeric($this->filter['time_sign_from'])) {
            $where[] = 'mosDTW.time_sign >=' . intval($this->filter['time_sign_from'] * 1000);
        }

        if (is_numeric($this->filter['time_sign_to'])) {
            $where[] = 'mosDTW.time_sign <=' . intval($this->filter['time_sign_to'] * 1000);
        }

        if (is_numeric($this->filter['point_per_sec_from'])) {
            $where[] = 'mosDTW.point_per_sec >=' . intval($this->filter['point_per_sec_from']);
        }

        if (is_numeric($this->filter['point_per_sec_to'])) {
            $where[] = 'mosDTW.point_per_sec <=' . intval($this->filter['point_per_sec_to']);
        }

        if (is_numeric($this->filter['DTW_from'])) {
            $where[] = 'mos.signature_DTW_mp_Cost >=' . intval($this->filter['DTW_from']);
        }

        if (is_numeric($this->filter['DTW_to'])) {
            $where[] = 'mos.signature_DTW_mp_Cost <=' . intval($this->filter['DTW_to']);
        }

        if ($this->filter['personal_name']) {
            $arr_ids=execSQL_line('select pkey from obj_site_personals where clss=211 and obj_name like "%' .
                                    addslashes($this->filter['personal_name']) . '%" or propusk like "' . addslashes($this->filter['personal_name']) .
                                    '" or driving like "' . addslashes($this->filter['personal_name']) . '" or tab_number like "' . addslashes($this->filter['personal_name']).'"') ;
            if (_sizeof($arr_ids)) {
                $where[] = 'mos.member_id in (' . implode(',', $arr_ids). ')';
            } else {
                $where[] = 'mos.member_id=0';
            }
        }

        if ($this->filter['has_standart']) {
            if ($this->filter['has_standart'] > 0) {
                $where[] = 'osp.sign_id > 0';
            } else {
                $where[] = '(osp.sign_id = 0 OR osp.sign_id is null)';
            }
        }

        if ($this->filter['valid']) {
            if ($this->filter['valid'] > 0) {
                $where[] = 'mos.DTW_res > 0';
            } else {
                $where[] = '(mos.DTW_res = 0 OR mos.DTW_res is null)';
            }
        }

        if (is_numeric($this->filter['time_deviation_from'])) {
            $tdd = 100 - intval($this->filter['time_deviation_from']);
            $where[] = "FLOOR($tdd * st_mosDTW.time_sign / 100) >= mosDTW.time_sign";
        }

        if (is_numeric($this->filter['time_deviation_to'])) {
            $tdd = 100 - intval($this->filter['time_deviation_to']);
            $where[] = "FLOOR($tdd * st_mosDTW.time_sign / 100) <= mosDTW.time_sign";
        }

        return implode(' and ', $where) ;
    }

    function panel_info_filter()
    {
        $_str=array() ; $info=array() ; $title='' ;

        if ($this->filter['data_from']) {
            $info['с']=$this->filter['data_from'];
        }

        if ($this->filter['data_to']) {
            $info['по']=$this->filter['data_to'];
        }

        if ($this->filter['personal_name']) {
            $info['Сотрудник']='"'.$this->filter['personal_name'].'"';
        }

        if (intval($this->filter['terminal']) > 0) {
            $terminals = $this->get_terminals();
            $info['Терминал']='"'.(isset($terminals[$this->filter['terminal']]) ? $terminals[$this->filter['terminal']] : $this->filter['terminal']).'"';
        }

        if (is_numeric($this->filter['point_count_from'])) {
            $info['Количество точек']['от'] = $this->filter['point_count_from'];
        }
        if (is_numeric($this->filter['point_count_to'])) {
            $info['Количество точек']['до'] = $this->filter['point_count_to'];
        }

        if (is_numeric($this->filter['time_sign_from'])) {
            $info['Продолжительность подписи']['от'] = $this->filter['time_sign_from'];
        }
        if (is_numeric($this->filter['time_sign_to'])) {
            $info['Продолжительность подписи']['до'] = $this->filter['time_sign_to'];
        }

        if (is_numeric($this->filter['point_per_sec_from'])) {
            $info['Количество точек в секунду']['от'] = $this->filter['point_per_sec_from'];
        }
        if (is_numeric($this->filter['point_per_sec_to'])) {
            $info['Количество точек в секунду']['до'] = $this->filter['point_per_sec_to'];
        }

        if (is_numeric($this->filter['DTW_from'])) {
            $info['Отклонение по форме']['от'] = $this->filter['DTW_from'];
        }
        if (is_numeric($this->filter['DTW_to'])) {
            $info['Отклонение по форме']['до'] = $this->filter['DTW_to'];
        }

        if (is_numeric($this->filter['time_deviation_from'])) {
            $info['Отклонение по времени']['от'] = $this->filter['time_deviation_from'];
        }
        if (is_numeric($this->filter['time_deviation_to'])) {
            $info['Отклонение по времени']['до'] = $this->filter['time_deviation_to'];
        }

        if ($this->filter['has_standart']) {
            $info['Эталонная подпись']='"'.(($this->filter['has_standart'] == 1) ? "Есть" : "Нет").'"';
        }

        if ($this->filter['valid']) {
            $info['Результат']='"'.(($this->filter['valid'] == 1) ? "Верна" : "Не верна").'"';
        }

        if (_sizeof($info)) foreach($info as $title => $value) {
            if (!is_array($value)) {
                $_str[] = $title . ': <strong>' . $value . '</strong>';
            } else {
                $t_str = array();
                foreach($value as $key => $val) {
                    $t_str[] = $key . ': <strong>' . $val . '</strong>';
                }

                $_str[] = $title . ' ' . implode(' ', $t_str);
            }
        }

        if (_sizeof($_str)) {
            $title='<div class="center">'.implode(' ', $_str).'</div>';
        }

        return $title ;
    }

    function get_from_query()
    {
        $query = " obj_site_mo_session as mos "
                . " inner join obj_site_personals as osp on osp.pkey = mos.member_id and osp.clss = 211"
                . " inner join obj_site_mo_session_DTW as mosDTW on mosDTW.parent = mos.pkey "
                . " left join obj_site_mo_session_DTW as st_mosDTW on st_mosDTW.pkey = osp.sign_id ";
        return $query;
    }

    function get_cnt_items($where, $options=array())
    {
        return execSQL_value('select count(mos.pkey) from  '. $this->get_from_query().' where '.$where, $options) ;
    }

    function get_order() {
        $order = "mos.pkey";
        switch ($this->filter['orderby']) {
            case 'date':
                $order = 'mos.c_data';
                break;
            case 'name':
                $order = 'osp.obj_name';
                break;
            case 'age':
                $order = 'osp.age';
                break;
            case 'point_count':
                $order = 'mosDTW.point_count';
                break;
            case 'time_sign':
                $order = 'mosDTW.time_sign';
                break;
            case 'point_per_sec':
                $order = 'mosDTW.point_per_sec';
                break;
            case 'cost':
                $order = 'mos.signature_DTW_mp_Cost';
                break;
            case 'time_deviation':
                $order = '(mosDTW.time_sign/st_mosDTW.time_sign)';
                break;
            case 'standart':
                $order = 'osp.sign_id';
                break;
            case 'standart':
                $order = 'osp.sign_id';
                break;
            case 'result':
                $order = 'mos.DTW_res';
                break;
        }

        return ' order by ' . $order . (($this->filter['order']) ? ' asc' : ' desc');
    }
    function get_items($where, $options=array())
    {
        $limit = ($options['limit']) ? ' ' . $options['limit'] : '';
        $order = $this->get_order();
        //$list_rec=execSQL('select * from  '.ENGINE()->table_mo_log.' where '.$usl.$order.$limit,$options,1) ;
        $query = "select mos.*, mosDTW.pkey as signature_key, mosDTW.obj_name as signature, "
                        . " mosDTW.point_count, mosDTW.time_sign, mosDTW.point_per_sec,"
                        . " osp.obj_name as member_name, osp.age as member_age, osp.pol as member_sex"
                        . " from " . $this->get_from_query()
                        . " where " . $where .  $order . $limit;
        $list_rec = execSQL($query, $options, 1);
        return $list_rec;
    }


    function print_template_HTML2($list_recs,$options)
    { /* ?><table class="basic fz_small <?if (!$this->filter['no_full_width']) echo 'full'?> auto">
          <tr>
              <th>ID</th>
              <th>Событие</th>
              <th>Время</th>
              <th>Зона доступа</th>
              <th>Турникет</th>
              <th>Направление</th>
              <th>Результат</th>
              <th>Ф.И.О.</th>
              <th>Пропуск</th>
          </tr>
        <? //$i=($options['first_obj'])? $options['first_obj']:1;
           if (_sizeof($list_recs)) foreach($list_recs as $rec)
           { ?><tr>
                   <td><?echo $rec['pkey']?></td>
                   <td><?echo $_SESSION['ARR_evt_type'][$rec['evt_type']]?></td>
                   <td><?echo date('d.m.Y H:i:s',$rec['c_data'])?>
                        <?if ($rec['_turn_stream_name']){?>&nbsp;<span class="v2" cmd="tracking/get_video_to_pass" stream="<?echo $rec['_turn_stream_name']?>" evt_id="<?echo $rec['pkey']?>"><i class="fa fa-video-camera"></i></span><?}?>
                   </td>
                   <td class="left"><?echo SKD()->get_full_zone_path($rec['zone_id'])?></td>
                   <td class="left"><?echo $_SESSION['ARR_device_name_small'][$rec['_device_clss']].'' ;
                                     if ($rec['_device_id']) echo $rec['_device_id'] ; else echo $rec['_device_turn_id'];
                       ?></td>
                   <td><?echo (!$rec['access_type'])? 'Вход':'Выход'?></td>
                   <td><?echo ($rec['result'])? '<span class="green">OK</span>':'<span class="red">'.$rec['obj_name'].'</span>'?></td>
                   <td class="left"><a href="/cab/bp/person/<?echo $rec['person_id']?>/" class="new_window" title="win_second"><?echo $rec['_person_fio']?></a></td>
                   <td class="left"><?if ($rec['pass_id']) { echo $_SESSION['ARR_pass_type_small'][$rec['pass_type']]?> № <?echo $rec['pass_id']?><?}
                                      if ($rec['pass_image']) {?><i class="fa fa-file-image-o fz_18 v2" cmd="aspmo_bp/get_gate_pass_image" event_id="<?echo $rec['pkey']?>"></i><?}

                       ?></td>
               </tr>
          <?}
        ?>
        </table><?

        $this->panel_info_select($options) ;
    */
    }

    function print_template_HTML($list_recs,$options=array())
    {
        $terminals = $this->get_terminals();
      ?><table class="basic fz_small <?if (!$this->filter['no_full_width']) echo 'full'?> auto list_logs_events" <?echo $id?>>
          <colgroup><col id=c1><col id=c2><col id=c3><col id=c3><col id=c4><col id=c5><col id=c6><col id=c7></colgroup>
          <thead>
              <tr>
                   <th>ID подписи</th>
                   <th>Дата, время</th>
                   <th>Терминал</th>
                   <th>Сотрудник</th>
                   <th>Возраст</th>
                   <th>Пол</th>
                   <th>Кол-во МО</th>
                   <th>Кол-во точек</th>
                   <th>Продолжительность подписи</th>
                   <th>Кол-во точек в секунду</th>
                   <th>Комментарий</th>
                   <th>Результат</th>
               </tr>
          </thead>
          <tbody>

          <?
          if (_sizeof($list_recs)) foreach ($list_recs as $rec)
          {
                  $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=" . $rec['member_id']);

                  $cnt=execSQL_value('select count(mos.pkey) from obj_site_mo_session as mos '
                                      . 'inner join obj_site_mo_session_DTW as mos_DTW on mos_DTW.parent = mos.pkey '
                                      . 'inner join obj_site_personals as pers on pers.pkey = mos.member_id '
                                      . 'where member_id=' . $rec['member_id']) ;

                  $rec_personal=PERSONAL()->get_personal_by_id($rec['member_id']) ;
              ?>
              <tr id="tr_<?echo $rec['pkey']?>">
                  <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 (isset($terminals[$rec['terminal_id']]) ? $terminals[$rec['terminal_id']] : $rec['terminal_id']);?></td>
                  <td><a href="/cab/personal/person/<?echo $rec['member_id']?>/sv/" class="new_window"><?echo $rec['member_name'];?></a></td>
                  <td><?echo $rec['member_age']?></td>
                  <td><?echo ($rec['member_sex'] == 0) ? "Муж." : "Жен.";?></td>
                  <td><?echo $cnt;?></td>
                  <td><?echo $rec['point_count'];?></td>
                  <td><?echo number_format($rec['time_sign'] / 1000, 3);?></td>
                  <td><?echo $rec['point_per_sec'];?></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 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 (($rec_norm['time_sign'] > 0) ? floor((1 -$rec['time_sign'] / $rec_norm['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><?
          }
      ?></tbody></table>
        <div style="display:none">awefawef
            <script type="text/javascript">
                $j(document).ready(function()
                {
                  $j('td.preview_graf').hover(preview_graf_on,preview_graf_off) ;
                }) ;

                function preview_graf_on()
                {
                    $j(this).find('div.panel_preview').show() ;
                    if ($j(this).find('div.panel_preview').html()=="")
                    {
                        var sv_id = $j(this).find('div.panel_preview').attr('sv_id');
                        var st_id = $j(this).find('div.panel_preview').attr('st_id');
                        send_ajax_request({cmd:'aspmo_sv/draw_preview',sv_id: sv_id, st_id: st_id}) ;
                    }
                }
                function preview_graf_off()
                {
                    $j(this).find('div.panel_preview').hide() ;
                }
            </script>
        </div>
      <? $this->panel_info_select($options) ;
    }
}

?>
