<?php
class report_error_messages extends c_report
{
    var $title='Сообщения о неисправностях на терминалах' ;

    function setting()
    {
        $type_errors = NOTIFY()->get_type_errors();
        ?><div id="panel_filter">
        <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo $this->url_report?>">
            <fieldset>
                <div class="row">
                    <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>
                    <?$this->filter_section_select('type_error','Тип ошибки:',2,$type_errors) ;?>
                </div>
            </fieldset>
            <?$this->panel_buttons();?>
        </form>
        </div>
        <?
    }

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

        if ($this->filter['data_from'])                       $info['c']=$this->filter['data_from'] ;
        if ($this->filter['data_to'])                         $info['по']=$this->filter['data_to'] ;
        if ($this->filter['type_error'])                         $info['тип ошибки']=$this->filter['type_error'] ;

        if (_sizeof($info)) foreach($info as $title=>$value)   if (is_array($value)) $_str[]=$title.': <strong>'.implode(', ',$value).'</strong>' ; else $_str[]=$title.': <strong>'.$value.'</strong>' ;
        if (_sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
        return $title ;
    }

    function create_usl_select_obj($_params,&$options)
    {
        $usl='' ;

        // время передаваемое в текстовом формате
        if ($this->filter['data_from'])     { $_usl[]='c_data>='.strtotime($this->filter['data_from']) ; if ($options['debug']) echo 'Дата от '.date('d.m.Y H:i:s',strtotime($this->filter['data_from'])).'<br>' ; }
        if ($this->filter['data_to'])       { $_usl[]='c_data<='.strtotime($this->filter['data_to']) ; if ($options['debug']) echo 'Дата до '.date('d.m.Y H:i:s',strtotime($this->filter['data_to'])).'<br>' ; }
        if ($this->filter['type_error'])       { $_usl[]='type_error="'.$this->filter['type_error'].'"' ; }

        if (_sizeof($_usl)) $usl=implode(' and ',$_usl) ;
        return($usl) ;
    }

    function get_cnt_items($usl,$options=array())
    {
        if ($usl) $usl = 'where '.$usl;
        $count=execSQL_value('select count(pkey) 
                              from error_messages '.$usl,$options);
        return($count) ;
    }

    function get_items($usl,$options=array())
    {
        if ($usl) $usl = 'where '.$usl;
        $limit=($options['limit'])? ' '.$options['limit']:'' ;
        $order=' order by c_data desc, pkey desc';
        $recs=execSQL('select *
                       from error_messages '.$usl.$order.$limit,$options);
        return($recs) ;
    }

    // шаблон - вывод ссылками без разделителя
    function print_template_HTML($list_recs,$options=array())
    {
        ?>
        <table class="list_personal_table_img basic fz_small full auto">
            <tr>
                <th>ID</th>
                <th>Дата</th>
                <th>Тип ошибки</th>
                <th>Краткое описание</th>
                <th>Заголовок сообщения</th>
                <th>Текст сообщения</th>
            </tr>
            <?if ($list_recs) foreach ($list_recs as $rec) {?>
                <tr <?if ($rec['new']) echo 'class="red"';?>>
                    <td><?echo $rec['pkey']?></td>
                    <td><?echo date('d.m.Y H:m',$rec['c_data'])?></td>
                    <td><?echo $rec['type_error']?></td>
                    <td><?echo $rec['brief_desc']?></td>
                    <td><?echo $rec['title_message']?></td>
                    <td><?echo $rec['text_message']?></td>
                </tr>
            <?}?>
        </table>
        <?
        NOTIFY()->update_status_messages();
    }

}
