<?php
// специальный отчет для добавления сотрудников в группы
//include_once(_DIR_EXT.'/events_media/i_event_docs.php');
class report_events_quiz_personals extends c_report
{
 var $title='Участники мероприятия' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $rec_event=array() ;
 var $event_group_id=0 ;
 var $event_id=0 ;
 var $group_id=0 ;
 var $personal_id=0 ;
 var $quiz_section_id=0 ;
 var $ids=0 ;
 var $status=0 ;


 function init($options=array())
 {  if ($this->event_id)
    { $this->rec_event=EVENTS()->get_event_by_id($this->event_id) ;
      if (!$this->rec_event['viewer_name']) $this->rec_event['viewer_name']='view_personals_active' ;
    }
    /*if ($this->quiz_section_id)
    { // получаем все фильтры всех дочерних разделов и свой
      $arr_sections_ids=QUIZ()->get_child_sections($this->quiz_section_id,1) ;
      $recs=execSQL('select pkey,filter from quiz_themes where pkey in ('.implode(',',$arr_sections_ids).')') ;
      damp_array($recs);

      $filter=json_decode($this->rec_section['filter'],true) ;
      //damp_array($filter);
      $report_obj->filter=$filter;
    }*/



 }
 // TODO filter
 function setting($options=array())
 {   if (!is_array($options['disabled_filter'])) $options['disabled_filter']=array() ;

     //$arr_orgs_ids=PERSONAL()->get_arr_orgs_to_cur_account('',['viewer_name'=>$this->rec_event['viewer_name']]) ;
     //$arr_otdel_ids=(_sizeof($this->filter['org_ids']))? PERSONAL()->get_arr_otdels_to_cur_account($this->filter['org_ids'],'',['viewer_name'=>$this->rec_event['viewer_name']]):array() ;
     //$arr_workd_ids=PERSONAL()->get_arr_works_to_cur_account($this->rec_event['_ext_info']['usl_select'],$this->filter['org_ids'],$this->filter['otdel_ids']) ;

     $this->form_open() ;
     $this->row_open() ;
     $this->filter_section_input_text('name','ФИО:',3,array('auto_complete'=>"autocomplette_personal_name")) ;
                          ////$this->filter_section_select_multiple('org_ids','Организация:',3,$arr_orgs_ids) ;
                          ////$this->filter_section_select_multiple('otdel_ids','Подразделение:',3,$arr_otdel_ids) ;
                          ////$this->filter_section_select_multiple('working_ids','Должность:',3,$arr_workd_ids) ;
     ////$this->filter_section_select_multiple('group_pers','Группа сотрудников:',3,_IL('IL_groups')->recs) ;
                          ////$this->filter_section_select_multiple('group_medic','Группа по болезни:',3,_IL('IL_group_medic')->recs) ;
                          ////$this->filter_section_input_text('age_from','Возраст, от:',2) ;
                          ////$this->filter_section_input_text('age_to','Возраст, до:',2) ;
                          //$this->filter_section_select('status','Статус:',2,EVENT_PMO()->arr_status) ;
     $this->row_close() ;
     $this->panel_buttons() ;
     $this->form_close() ;
  }


  function create_usl_select_obj($_params=array(),&$options=array())
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     //$usl[]='t1.clss=211 and t1.enabled=1' ;
     $usl[]='1' ;
     if ($this->ids)                     $usl[]='t1.pkey in ('.$this->ids.')' ;
     if ($this->filter['name'])          $usl[]='t1.obj_name like "%'.$this->filter['name'].'%"' ;

     if ($this->status==1)         $usl[]='(t2.status=1 or t2.status is null)' ;
     else  if ($this->status==2)   $usl[]='t2.status in ('.$this->status.')' ;
     else  if ($this->status==3)   $usl[]='t2.status in ('.$this->status.')' ;


if ($this->filter['name']) $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;
     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl) ;
     // damp_array($this->rec_event) ;
     return($usl_res) ;
  }

  function get_arr_info_filters()
  { $info=parent::get_arr_info_filters() ;
    //if ($this->filter['status'])  $info['Статус']=EVENT_PMO()->arr_status[$this->filter['status']] ;
    return $info ;
  }


 function get_cnt_items($usl,$options=array())
  { //$options['debug']=2 ;
    // вариант когда не заданы собственные условия отбора - надо смотреть по конкретному участию
   /* $cnt=execSQL_value('select count(t2.pkey)
                       from obj_site_events_pass as t2
                       left join obj_site_events_pass t2 on t2.personal_id=t1.pkey and t2.event_id='.$this->event_id.'
                       where t2.event_id='.$this->event_id.' '.$usl,$options) ;

    */
    // если заданы условия отюлра участников - смоттри по вьюверу
    //
      $cnt=execSQL_value('select count(t1.pkey) 
                         from '.$this->rec_event['viewer_name'].' as t1
                         left join obj_site_events_pass t2 on t2.personal_id=t1.pkey and t2.event_id='.$this->event_id.'
                         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 obj_name' ;
    $order=' order by pkey desc' ;
    //$options['debug']=2 ;
    $list_rec=execSQL('select t1.*,
                       t2.pkey as event_pass_id,t2.status as event_pass_status,t2.r_data as data_event_pass_status_change 
                       from '.$this->rec_event['viewer_name'].' as t1
                       left join obj_site_events_pass t2 on t2.personal_id=t1.pkey and t2.event_id='.$this->event_id.'
                       where '.$usl.$order.$limit,$options) ;
    if (_sizeof($list_rec)) foreach($list_rec as $id=>$rec) PERSONAL()->prepare_public_info_to_personal($list_rec[$id],$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    $event_obj=EVENTS()->get_event_obj_by_id($this->event_id) ;

    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <tr>
            <th>ID</th>
            <th>ФИО, дата рождения, Возраст</th>
            <th>Организация, подразделение</th>
            <th>Статус контроля знаний</th>
            <th>Дата доведения</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec_personal)
        {   //if ($rec_event_pass['event_id']) $rec_event=EVENTS()->get_event_by_id($rec_event_pass['event_id']) ;  else $rec_event=array() ;
            //if ($rec_event_pass['scan_id']) $rec_scan=DOCS()->get_scan_by_id($rec_event_pass['scan_id']) ;        else $rec_scan=array() ;
            //if ($rec_event_pass['doc_id']) $rec_doc=DOCS()->get_doc_by_id($rec_event_pass['doc_id']) ;            else $rec_doc=array() ;
            //if ($rec_event_pass['personal_id']) $rec_personal=PERSONAL()->get_personal_by_id($rec_event_pass['personal_id']) ;            else $rec_personal=array() ;
            //damp_array($rec_event) ;
            //damp_array($rec_scan) ;
            //damp_array($rec_event_pass) ;
            //damp_array($rec_personal) ;
            ?><tr class=item>
                <td><a href="/window/events/event_pass/<?echo $rec_personal['event_pass_id']?>/" class="new_window"><?echo $rec_personal['event_pass_id']?></a></td>
                <td class="left"><a href="<?echo $rec_personal['__href_window']?>" class="new_window" target="_blank" title="win_second"><?echo $rec_personal['obj_name']?></a>
                    <?  /*if ($rec['uid']) echo '<br><span class="nowrap small">'.$rec['uid'].'</span>' ;*/
                        if (!$rec_personal['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec_personal['fired_data']).')' ;
                        if ($rec_personal['dr'])echo '<br>'.$rec_personal['dr'] ;
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec_personal['_org_name'].'</strong><br><div class="small">'.$rec_personal['_otdel_name'].'</div>'._IL('IL_works')->recs[$rec_personal['working']]['obj_name']?></td>
                <td><?if ($rec_personal['event_pass_status']) echo $event_obj->arr_status[$rec_personal['event_pass_status']]?></td>
                <td><?if ($rec_personal['data_event_pass_status_change']) echo date('d.m.Y H:i',$rec_personal['data_event_pass_status_change'])?></td>

            </tr><?
        }
      ?></table>
      <style type="text/css">
                      table.list_personal_table_img{}
                      table.list_personal_table_img td.cnt_mess{font-size:22px;color:green;}
                      table.list_personal_table_img td.cnt_mess a{text-decoration:none;}
                      table.list_personal_table_img td.cnt_mess a:hover{text-decoration:underline;}
                      table.list_personal_table_img div.view_cnt{font-size:24px;margin:5px 0;}
                      table.list_personal_table_img div.view_data{font-size:14px;margin:5px 0;}
                      table.list_personal_table_img div.mess_status{font-size:14px;margin:5px 0;font-weight:bold;}
                      table.list_personal_table_img div.mo_alert{color:white;font-size:15px;margin-top:10px;background:darkred;padding:10px;}
                  </style>
      <?
      //damp_array($rec) ;
  }


}

?>
