<?php
include_once("c_setting_members.php");
class c_page_cab_setting_members_groups extends c_page_cab_setting_members
{
  public $h1='Рабочие группы ЭСМО' ;
  var $arr_mo_type=array(0=>'Все',1=>'Только предсменные',2=>'Только послесменные') ;

  function second_menu_config()
  { $this->second_menu['/cab/setting/members/']=array('title'=>'Настройки ЭСМО') ;
    $this->second_menu['/cab/setting/members/groups/']=array('title'=>'Рабочие группы ЭСМО') ;
    if (function_exists('ENTERPRISE')) $this->second_menu['/cab/enterprise/setting/groups/']=array('title'=>'Рабочие группы ПРЕДПРИЯТИЕ') ;
  }

 function block_main()
 { $this->page_title() ;
   $this->panel_list_edit() ;
 }

 function panel_list_edit()
{ $recs_group=execSQL('select * from obj_site_account where clss in (1,206) and enabled=1 and parent>=0') ;
  $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'] ;
  }
  //damp_array($recs_account) ;
  //damp_array($recs_terminal) ;
  //damp_array($recs_arm) ;

  $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'] ;
  //damp_array($arr_group_org) ;
  $items_filters_sets=PERSONALS_FILTER()->get_personals_filter_all() ;

  $list_groups=TREE('obj_site_account')->get_list_strukture('clss in (1,206)',null,0) ;
  ?><table id="groups_list_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 ($list_groups) foreach($list_groups as $group_id=>$group_name)
       {  $rec_group=$recs_group[$group_id];
          $filters_set=$items_filters_sets[$rec_group['_reffer']] ;
          $setting=unserialize($rec_group['settings']) ;
          if (!$setting) $setting=json_decode($rec_group['settings'],true) ;
          if (!$setting['timezone']) $setting['timezone']='Europe/Moscow' ;
          ?><tr><td class="left"><?echo $group_id?></td>
               <td class="left nowrap"><a href="/window/setting/members/group/<?echo $group_id?>/" class="new_window"><?echo $group_name?></a></td>
               <td class="left"><div style="max-height:100px;overflow:auto;"><?if (_sizeof($recs_account[$rec_group['pkey']])) echo implode('<br>',$recs_account[$rec_group['pkey']])?></div></td>
               <td class="left"><div style="max-height:100px;overflow:auto;"><?if (_sizeof($recs_terminal[$rec_group['pkey']])) echo implode('<br>',$recs_terminal[$rec_group['pkey']])?></div></td>
               <td class="left"><div style="max-height:100px;overflow:auto;"><?if (_sizeof($recs_arm[$rec_group['pkey']])) echo implode('<br>',$recs_arm[$rec_group['pkey']])?></div></td>
               <td><?echo $setting['timezone']?></td>
               <td><?echo $this->arr_mo_type[$setting['mo_type']]?></td>
               <td><?   if ($arr_group_org[$group_id]) echo 'Организации: <strong><a href="" class="v2" cmd="aspmo_setting/view_group_filter" group_id="'.$group_id.'">Да</a></strong><br>'  ; //.implode(', ',$arr_group_org[$group_id]).'</strong><br>' ;
                        if (_sizeof($filters_set)) echo 'Фильтр по сотрудникам: <strong><a href="" class="v2" cmd="aspmo_setting/view_group_filter" group_id="'.$group_id.'">Да</a></strong><br>' ; // ;
                   ?>
               </td>
          </tr><?
       }?>
   </table>
    <?

}


}



?>
