<?php
class report_work_groups extends c_report
{
    var $title='Отчет по рабочим группам ЭСМО' ;
    var $view_by_space_filter=1 ;

    function setting($options=array())
    {
        $arr_groups=ACCOUNTS()->get_arr_groups_to_cur_account() ;
        ?><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" id="person_info">
                    <?
                    $this->filter_section_select('group_id',$GLOBALS['LS_person_group_title'].':',2,$arr_groups) ;
                    ?>
                </div>
            </fieldset>
            <?$this->panel_buttons();?>
        </form>
        </div><br>
        <?
    }

    function HTML_report_body($options=array())
    {
        if ($this->filter['group_id']) $_usl[]='pkey='.$this->filter['group_id'];

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

        $recs_group=execSQL('select * from obj_site_account where clss in (1,206) and enabled=1 and parent>=0'.$usl) ;

        $recs_account=array() ;  $recs_terminal=array() ;  $recs_arm=array() ;
        $recs=execSQL('select pkey,obj_name,parent,group_id,clss,ip from obj_site_account where clss in (203,205,210) and enabled=1') ;
        if (_sizeof($recs)) foreach($recs as $rec)
            switch($rec['clss'])
            { case 203: $recs_terminal[$rec['parent']][]=$rec['obj_name'].' ['.$rec['ip'].']' ; break ;
                case 205: $recs_arm[$rec['parent']][]=$rec['obj_name'].' ['.$rec['ip'].']' ; break ;
                case 210: if ($rec['group_id']) $recs_account[$rec['group_id']][]=$rec['obj_name'] ;
                else                  $recs_account[$rec['parent']][]=$rec['obj_name'] ;
            }

        $arr_group_org=array() ;
        $recs_groups=execSQL('select group_id,pkey,obj_name from obj_site_personals where clss=207 and group_id>0',0,1) ;
        if (_sizeof($recs_groups)) foreach($recs_groups as $rec) $arr_group_org[$rec['group_id']][$rec['pkey']]=$rec['obj_name'] ;

        ?>
        <table class="basic fz_small full auto">
            <tr>
                <th>ID</th>
                <th>Наименование</th>
                <th>Персонал ЭСМО</th>
                <th>Терминалы</th>
                <th>АРМ</th>
                <th>Часовой пояс</th>
                <th>Привязанные организации</th>
                <th>Фильтр по сотрудникам</th>
            </tr>
            <?if ($recs_group) foreach($recs_group as $rec)
            {  $setting=unserialize($rec['settings']) ;
                if (!$setting['timezone']) $setting['timezone']='Europe/Moscow' ;
                ?><tr>
                <td class="left"><?echo $rec['pkey']?></td>
                <td class="left"><!--<a href="/window/setting/group/<?echo $rec['pkey']?>/">--><?echo htmlspecialchars($rec['obj_name'])?><!--</a>--></td>
                <td class="left" style="max-height:100px;min-height:30px;overflow:auto;display:block;"><?if (_sizeof($recs_account[$rec['pkey']])) echo implode('<br>',$recs_account[$rec['pkey']])?></td>
                <td class="left"><?if (_sizeof($recs_terminal[$rec['pkey']])) echo implode('<br>',$recs_terminal[$rec['pkey']])?></td>
                <td class="left"><?if (_sizeof($recs_arm[$rec['pkey']])) echo implode('<br>',$recs_arm[$rec['pkey']])?></td>
                <td class="left"><?echo $setting['timezone']?></td>
                <td class="left"><?   if ($arr_group_org[$rec['pkey']]) echo '<strong>'.implode(', ',$arr_group_org[$rec['pkey']]).'</strong>' ;?></td>
                <td class="left"><?   PERSONALS_FILTER()->get_personals_filter_info_to_item($rec['_reffer']) ;?> </td>
                </tr><?
            }?>
        </table>
        <?

    }

}
