<?php
include_once("c_AD_setting.php");
class c_page_cab_AD_setting_group extends c_page_cab_AD_setting
{
  public $h1='Рабочие группы персонала ЭСМО - ActiveDirectory' ;

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

 function panel_list_edit()
{  //$GLOBALS['debug_indx_list']=1 ;

  $recs_AD=execSQL('select pkey,obj_name,id,group_id,personal_id,enabled from view_IL_ad_groups order by obj_name') ;
  $recs_group=execSQL('select * from obj_site_account where clss in (1,206) and enabled=1 and parent>0') ;
  $recs_AD_by_group=array() ;
  $recs_AD_to_rol=execSQL('select pkey,id,obj_name,group_id from view_IL_ad_groups where group_id>0') ;
  if (_sizeof($recs_AD_to_rol)) foreach($recs_AD_to_rol as $rec_group_AD) $recs_AD_by_group[$rec_group_AD['group_id']][$rec_group_AD['id']]=$rec_group_AD['obj_name'] ;

  $recs_account=array() ;  $recs_terminal=array() ;  $recs_arm=array() ;
  $recs=execSQL('select 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'] ;
  }

  ?><form>
    <button class="v2" cmd="aspmo_setting/save_ESMO_group">Сохранить изменения</button>
    <table class="basic fz_small"><tr><th>ID</th><th>Рабочая группа ЭСМО</th><th>Группы ActiveDirectory</th></tr>
     <?if ($recs_group) foreach($recs_group as $rec_RG)
       { ?><tr><td class="left"><?echo $rec_RG['pkey']?></td>
               <td class="left"><?echo $rec_RG['obj_name']?></td>
               <td class="left">
                   <select name="recs_group[<?echo $rec_RG['pkey']?>][groups_AD][]" style="width:400px;" multiple="multiple"><option value="0">Нет соответствия</option>
                     <? foreach($recs_AD as $rec_AD) {?><option value="<?echo $rec_AD['id']?>" <?if (isset($recs_AD_by_group[$rec_RG['pkey']][$rec_AD['id']])) echo 'selected'?>><?echo $rec_AD['obj_name']?></option><?}?>
                   </select>
               </td>
          </tr><?
       }?>
   </table>
   </form>
  <?
}


}



?>
