<?php
class report_members_cryptopro extends c_report
{
 var $title='Персонал ЭСМО' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $group_id=0 ;
 public $use_datepicker=1 ;

 function setting($options=array())
    {   if ($this->filter['personal_id'] and !$this->filter['name']) $this->filter['name']=PERSONAL()->get_name_by_id($this->filter['personal_id']) ;
        $arr_groups=ACCOUNTS()->get_list_workgoups() ;
        $members=ACCOUNTS()->get_list_members() ;
        ?><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">
                             <section class="col col-2">
                                 <label class="label">Персонал</label>
                                 <label class="select">
                                     <select id="account_ids" name="filter[account_ids][]"  multiple="multiple"><option value="0">Все</option>
                                         <?if (_sizeof($members))foreach($members as $rec_member)
                                           {?><option value="<?echo $rec_member['pkey']?>" <?if (isset($this->filter['account_ids'][$rec_member['pkey']])) echo 'selected'?>><?=$rec_member['obj_name']?></option><?}
                                         ?>
                                     </select>
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Роль</label>
                                 <label class="select">
                                     <select name="filter[rol]"><option></option>
                                        <?if (_sizeof($_SESSION['ARR_roll'])) foreach($_SESSION['ARR_roll'] as $id=>$rec){?><option value="<?echo $id?>" <?if ($this->filter['rol']==$id) echo 'selected'?>><?echo $rec['obj_name']?></option><?}?>
                                     </select>
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="label">Группа</label>
                                 <label class="select">
                                     <select name="filter[group_id]"><option></option>
                                        <?if (_sizeof($arr_groups)) foreach($arr_groups as $id=>$rec){?><option value="<?echo $id?>" <?if ($this->filter['group_id']==$id) echo 'selected'?>><?echo $rec['obj_name']?></option><?}?>
                                     </select>
                                 </label>
                             </section>
                             <section class="col col-2">
                                 <label class="checkbox"><input name="filter[no_ecp]" type="checkbox" value="1"  <?if ($this->filter['no_ecp']) echo 'checked'?>><i></i> Без ЭЦП</label>
                                 <label class="checkbox"><input name="filter[is_emulate]" type="checkbox" value="1"  <?if ($this->filter['is_emulate']) echo 'checked'?>><i></i> С эмуляцией ЭЦП</label>
                             </section>
                           </div>
                     </fieldset>
                     <?$this->panel_button_apply();?>
                 </form>
          </div><br>
        <?
     }

  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='clss=210' ;
     if ($this->filter['name'])             $usl[]='obj_name like "'.$this->filter['name'].'%"' ;
     if (_sizeof($this->filter['account_ids']))     $usl[]='pkey in ('.implode(',',array_keys($this->filter['account_ids'])).')' ;
     if ($this->filter['rol'])              $usl[]='rol='.$this->filter['rol'].'' ;
     if ($this->filter['group_id'])         $usl[]='(group_id='.$this->filter['group_id'].' or parent='.$this->filter['group_id'].')' ;
     //if ($this->filter['no_ecp'])           $usl[]='sert_id=""' ;
     if ($this->filter['is_emulate'])       $usl[]='evulate_ECP=1' ;
     if ($this->filter['AD'])               $usl[]='UID!=""' ;
     if ($this->group_id)
     { $str_ids=ACCOUNTS()->tree[$this->group_id]->get_list_child() ;
       $usl[]='(group_id in ('.$str_ids.') or parent in ('.$str_ids.'))' ;
     }
     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl,1,-1) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   //damp_array($this->filter) ;
   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if (_sizeof($this->filter['account_ids']))
   {   $arr=array() ;
        foreach($this->filter['account_ids'] as $id=>$temp) $arr[]=ACCOUNTS()->get_member_name_by_id($id) ;
        $info['Персонал']=implode(',',$arr) ;
   }
   if ($this->filter['rol'])                             $info['Роль']='"'.$_SESSION['ARR_roll'][$this->filter['rol']]['obj_name'].'"' ;
   if ($this->filter['group_id'])                        $info['Группа']='"'.ACCOUNTS()->get_group_name($this->filter['group_id']).'"' ;
   if ($this->filter['no_ecp'])                          $info['Без ЭЦП']='Да' ;
   if ($this->filter['is_emulate'])                      $info['Эмуляция ЭЦП']='Да' ;
   if ($this->filter['AD'])                              $info['AD']='Да' ;

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


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

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by parent,rol,obj_name' ;
    //echo $usl ;
    //  $options['debug']=2 ;
 	$list_rec=execSQL('select *
                       from  view_account
                       where '.$usl.$order.$limit,$options) ;
    if (_sizeof($list_rec))
    { foreach($list_rec as $id=>$rec) ACCOUNTS()->prepare_public_info_to_member($list_rec[$id],$options) ;
    }
    return($list_rec) ;
  }


    // шаблон - вывод ссылками без разделитея
    function print_template_HTML($list_recs,$options=array())
    { ?><div id="report_membes"><?

       ?><table class="basic full fz_small auto">
         <tr>
            <th rowspan="2">Состояние</th>
            <th rowspan="2">Группа</th>
            <th rowspan="2">Имя</th>
            <th rowspan="2">IP</th>
            <th rowspan="2">Браузер</th>
            <th colspan="2">Криптопро</th>
            <th colspan="3">ЭЦП</th>
         </tr>
         <tr>
           <th>Плагин</th>
           <th>Криптопровайдер</th>
           <th>Владелец</th>
           <th>Действует до</th>
           <th>Осталось, дней</th>
         </tr>
        <?
       if (_sizeof($list_recs)) foreach($list_recs as $rec)
       {  $certificate=$rec['_ext_info']['certificate'] ;
          $cryptopro=$rec['_ext_info']['cryptopro'] ;
        ?>
        <tr><td><?echo ($rec['enabled'])? '<span class="green">включен</span>':'<span class="red">выключен</span>'?></td>
            <td><?if (isset(ACCOUNTS()->tree[$rec['group_id']])) echo ACCOUNTS()->tree[$rec['group_id']]->name?></td>
            <td class="left" style="width:200px;"><?if ($rec['UID']) echo '<i class="fab fa-windows" aria-hidden="true"></i> '?><a  class="new_window" target="_blank" title="window_member" href="<?echo $rec['__href_window']?>"><?echo htmlspecialchars($rec['obj_name'])?></a><br><?echo $rec['_rol_name']?></td>
            <td><?echo $rec['ip']?></td>
            <td><?echo $cryptopro['Browser']?></td>
            <td><?echo $cryptopro['PlugInVersion']?></td>
            <td><?echo $cryptopro['CSPVersion']?></td>
            <? if ($rec['evulate_ECP']) {?><td colspan="3"><span style="color:red;font-weight:bold;">Эмуляция</span></td><?}
               else
               {  ?><td><?echo $certificate['SubjectName']?></td>
                    <td><? if ($certificate['ValidToDate']) echo $certificate['ValidToDate'] ; ?></td>
                   <td><? if ($certificate['ValidToDate']) echo round((strtotime($certificate['ValidToDate'])-time())/24/60/60)  ?></td>
                  <?
               }
            ?>
         </tr>
     <?}?>
      </table><?
   ?></div><?
       // print_2x_arr($list_recs) ;
  }
}
?>
