<?php
include_once("c_setting_members.php");
class c_page_cab_setting_members_rol extends c_page_cab_setting_members
{
  public $h1='Роли персонала' ;

 function block_main()
 { global $member ;

   $this->page_title() ;
     after_init_system() ;
   //include_once('panel_list_edit.php');
   //panel_list_edit(array('title_list'=>'Роли персонала','title_create'=>'Новая роль','list_name'=>'IL_roll','read_only_id'=>$member->info['rol'])) ;
   $this->panel_list_edit() ;
     //damp_array($_SESSION['ARR_roll']) ;

 }



 function panel_list_edit()
{ $recs_account=execSQL('select pkey,obj_name,rol,enabled from obj_site_account where clss=210 and rol>0') ;
  $recs_rol_by_account=array() ;
  $recs_rol=execSQL('select * from roles order by id') ;
  if (_sizeof($recs_account)) foreach($recs_account as $rec_account)
  {   if (!$rec_account['enabled']) $rec_account['enabled']=0 ;
      $recs_rol_by_account[$rec_account['rol']][$rec_account['enabled']][]='<a class="new_window" target="_blank" title="window_member" href="/window/setting/member/'.$rec_account['pkey'].'/">'.$rec_account['obj_name'].'</a>' ;
  }
  //damp_array($recs_rol_by_account);
  ?><form>
    <button class="v2" cmd="aspmo_setting/rol_create">Создать новую роль</button> <button class="v2" cmd="aspmo_setting/save_rol">Сохранить изменения</button>
    <table class="basic fz_small"><tr><th>ID</th><th>Наименование</th><th>Активных аккаунтов</th><th>Заблокированных аккаунтов</th><th>Стартовая страница кабинета</th><th>Работа<br>по<br>сменам</th><th>Одна<br>смена<br>в группе</th><th>Шаблон отчета на закрытие смены</th><th>Должность<br>по умолчанию</th><th>Срок жизни сессии, секунд</th><th>Операции</th></tr>
     <?if ($recs_rol) foreach($recs_rol as $rec)
       {   $id=$rec['id'] ;
           ?><tr><td class="left"><?echo $id?><input type="hidden" name="roles[<?echo $rec['pkey']?>][id]" value="<?echo $rec['id']?>"></td>
               <td class="left"><input type="text" name="roles[<?echo  $rec['pkey']?>][name]"  class=big value="<?echo htmlspecialchars($rec['obj_name'])?>"></td>
               <td class="center"><? $this->show_account_info($id,'only_enabled',$recs_rol_by_account[$id][1]) ; ?></td>
               <td class="center"><? $this->show_account_info($id,'only_disabled',$recs_rol_by_account[$id][0]) ; ?></td>
               <td class="left"><?if ($id<100) echo $rec['index_page'].'<input type="hidden" name="roles['.$rec['pkey'].'][index_page]" value="'.$rec['index_page'].'">' ; else {?><input type="text" name="roles[<?echo $rec['pkey']?>][index_page]" style="width:300px;" value="<?echo htmlspecialchars($rec['index_page'])?>"><?}?></td>

               <td class="center"><?if ($id<100) echo ($rec['use_auch_as_smena'])? 'Да':'' ; ?></td>
               <td class="center"><?if ($id<100) echo ($rec['smena_monopole_mode'])? 'Да':'' ; ?></td>
               <td class="left"><?if ($id<100) echo $rec['report_template'] ; ?></td>
               <td class="left"><input type="text" name="roles[<?echo  $rec['pkey']?>][working]" class=big value="<?echo htmlspecialchars($rec['working'])?>"></td>
               <td class="left"><input type="text" name="roles[<?echo  $rec['pkey']?>][autologout]"  data-mask="00000000" data-mask-selectonfocus="true"  class=big value="<?echo htmlspecialchars($rec['autologout'])?>"></td>
                <td><a class="new_window" target="_blank" title="window_member" href="/window/setting/members/rol/card/<?echo $rec['id']?>/">Карточка роли</a>
                   <?if (!_sizeof($recs_rol_by_account[$id]) && $id>=100){?><button class="v2" cmd="aspmo_setting/rol_delete" rol_id="<?=$id?>">Удалить</button><?}?>
               </td>
          </tr><?
       }?>
   </table>
   <!--<br><button class="v2" cmd="list_rec_delete" list_name="IL_roll" rec_id="<?echo $id?>">Удалить выбранную роль</button>-->
   </form>
    <?
}

function show_account_info($rol_id,$status,$recs)
{
   $cnt=_sizeof($recs) ;
   if ($cnt)
   { echo '<a target="_blank"  href="/cab/setting/members/[rol='.$rol_id.',props=('.$status.')]/">'.$cnt.' '.get_case_by_count_1_2_5($cnt,'аккаунт, аккаунта, аккаунтов').'</a><br>' ;
     /*if ($cnt<=3) echo implode('<br>',$recs) ;
     else {?><div style="height:100px;overflow-y: scroll;"><? echo implode('<br>',$recs)?></div><?}*/
   }
}


}



?>
