<?php
// специальный отчет для добавления сотрудников в группы
class report_personals_in_event_poll_free 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 $obj_event=null ;
 var $rec_lession=array() ;
 var $event_group_id=0 ;
 var $event_id=0 ;
 var $group_id=0 ;
 var $arr_temp_fired=array(0=>'Без сотрудников в отложенном увольнении',1=>'Все сотрудники') ;

 function init($options=array())
 {
    if ($this->event_id)
    {   $this->obj_event=EVENTS()->get_event_obj_by_id($this->event_id) ;
        $this->rec_event=EVENTS()->get_event_by_id($this->event_id) ;
        $this->rec_lession=execSQL_van('select * from obj_site_lession where event_id='.$this->rec_event['pkey'].' order by pkey limit 1') ;


    }
 }

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

     list($arr_orgs_ids,$arr_otdel_ids,$arr_workd_ids)=PERSONAL()->get_org_otdels_works_to_cur_account($this->filter,'',$this->rec_event['_reffer']) ;

     ?><div id="panel_filter">
             <form id="sky-form" class="sky-form">
                 <input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                 <input type="hidden" name="filter[event_id]" value="<?echo $this->filter['event_id']?>">
                 <fieldset>
                     <div class="row">
                       <? $this->filter_section_input_text('name','ФИО:',2,array('auto_complete'=>"autocomplette_personal_name")) ;
                          $this->filter_section_select_multiple('org_ids','Организация:',2,$arr_orgs_ids) ;
                          $this->filter_section_select_multiple('otdel_ids','Подразделение:',2,$arr_otdel_ids) ;
                          $this->filter_section_select_multiple('working_ids','Должность:',2,$arr_workd_ids) ;
                          $this->filter_section_select('temp_fired','Отложенное увольнение:',2,$this->arr_temp_fired,array('nospace_element'=>1)) ;
                       ?>
                     </div>
                     <div class="row">
                       <? $this->filter_section_select_multiple('group_pers','Группа сотрудников:',2,_IL('IL_groups')->recs) ;
                          //$this->filter_section_select_multiple('group_medic','Группа по болезни:',3,_IL('IL_group_medic')->recs) ;
                          $this->filter_section_input_text('propusk','Пропуск:',2) ;
                          $this->filter_section_input_text('age_from','Возраст, от:',2) ;
                          $this->filter_section_input_text('age_to','Возраст, до:',2) ;
                       ?>
                     </div>
                 </fieldset>
                 <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Поиск">
                     <?
                     if ($this->rec_lession<2 and $this->obj_event->allow_send_invite)
                     {?><button class="button v2" cmd="events_poll/set_check_personal_to_status_2" event_id="<?echo $this->rec_event['pkey']?>" update_url="<?echo $this->rec_group['__href'].'edit/'?>">Пригласить на собрание выбранных</button>
                        <button class="button v2" cmd="events_poll/set_all_personal_to_status_2" event_id="<?echo $this->rec_event['pkey']?>" update_url="<?echo $this->rec_group['__href'].'edit/'?>">Пригласить на собраниe всех</button>
                      <?}
                      else if ($this->obj_event->allow_send_invite) echo '<div class="alert" style="text-align:center;">Вы не можете пригласить сотрудников на собрание, так как текущий статус собрания "'.$this->obj_event->arr_status_lession[$this->rec_lession['status']].'"</div>' ;
                      ?>
                 </div>
              <!--</form>-->
       </div><br>
     <?
  }


  function create_usl_select_obj($_params=array(),&$options=array())
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='clss=211' ;
     $usl[]='enabled=1' ;
     $usl[]='event_status=1' ;
     $usl[]='enabled=1' ;
     if ($this->event_id)                   $usl[]='event_id='.$this->event_id ;
     if ($this->filter['name'])             $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;
     if ($this->filter['org_ids'])          $usl[]='parent2 in ('.implode(',',array_keys($this->filter['org_ids'])).')' ;
     if ($this->filter['otdel_ids'])        $usl[]='parent3 in ('.implode(',',array_keys($this->filter['otdel_ids'])).')' ;
     if ($this->filter['personal_ids'])     $usl[]='pkey in ('.implode(',',array_keys($this->filter['personal_ids'])).')' ;
     if ($this->filter['propusk'])         $usl[]='propusk="'.$this->filter['propusk'].'"';
     if ($this->filter['age_from'])         $usl[]='age>='.$this->filter['age_from'];
     if ($this->filter['age_to'])           $usl[]='age<='.$this->filter['age_to'];
     if (!$this->filter['temp_fired'])      $usl[]='(fired_data=0 or fired_data is null)';
     if (_sizeof($this->filter['working_ids'])) $usl[]='working in ('.implode(',',array_keys($this->filter['working_ids'])).')' ;
     if (MEMBER()->personal_viewer_name) $usl['account_personal_filter']='pkey in (select pkey from '.MEMBER()->personal_viewer_name.')' ;
     if (_sizeof($this->filter['group_medic']))  $usl['group_medic']=$this->get_usl_group_medic('pkey',$this->filter['group_medic']) ;
     if (_sizeof($this->filter['group_pers'])) $usl['group_pers']=$this->get_usl_group_personal('pkey',$this->filter['group_pers']) ;
     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl,1,-1) ;
     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']] ;
    if (!$this->filter['temp_fired'])  $info['Отбор сотрудников']='Без отложенного увольнения';
    return $info ;
  }

 function get_cnt_items($usl,$options=array())
  { //$options['debug']=2 ;
    $cnt=execSQL_value('select count(pkey)
                        from  view_event_personals
                        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' ;
    //echo $usl ;
    //$options['debug']=2 ;
 	$list_rec=execSQL('select *
                       from view_event_personals
                       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']:'' ;
    $arr_personal_ids=array() ;
    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <colgroup><col id="c1"><col id="c2"><col id="c3"><col id="c4"></colgroup>
        <tr><th>Выбор</th>
            <th>ID</th>
            <th>ФИО, дата рождения, Возраст</th>
            <th>Организация, подразделение</th>
            <th>Должность</th>
            <th>Статус</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   ?><tr class=item>
                <td><?if (!in_array($rec['pkey'],$arr_personal_ids) and $rec['event_status']==1){?><input type="<?echo ($options['check_type'])? $options['check_type']:'checkbox'?>" name="_check[]" value="<?echo $rec['_reffer']?>"><?} else echo '<span class="red"></span>'?></td>
                <td><a href="/cab/events/pass/<?echo $rec['event_pass_id']?>/" class="new_window" target="_blank" title="win_pass_info"><?echo $rec['event_pass_id']?></a></td>
                <td class="left"><a href="<?echo $rec['__href_window']?>" class="new_window" target="_blank" title="win_second"><?echo $rec['obj_name']?></a>
                    <?  if ($rec['propusk']) echo '<br><span class="nowrap small">PASS: '.$rec['propusk'].'</span>' ;
                        if ($rec['uid']) echo '<br><span class="nowrap small">UID: '.$rec['uid'].'</span>' ;
                        if (!$rec['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec['fired_data']).')' ;
                        if ($rec['dr'])echo '<br>'.$rec['dr'] ;
                        if ($rec['age'])echo ', '.$rec['age'].' '.get_case_by_count_1_2_5($rec['age'],'год,года,лет');
                        if ($rec['fired_data'])echo '<div style="color:burlywood;">Отложенное увольнение до <strong>'.date('d.m.Y',$rec['fired_data']).'</strong></div>' ;
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec['_org_name'].'</strong><br><div class="small">'.$rec['_otdel_name'].'</div>'?></td>
                <td class="left"><?echo _IL('IL_works')->recs[$rec['working']]['obj_name']  ;
                    if ($rec['working2']) echo '<br><strong>Совмещение: </strong>'._IL('IL_works')->recs[$rec['working2']]['obj_name'] ;
                    ?></td>
                <td><?echo $this->obj_event->arr_status[$rec['event_status']]?></td>
            </tr><?
        }
      ?></table><?
      echo '</form>' ;
      //damp_array($rec) ;
  }


}

?>
