<?php
// специальный отчет для добавления сотрудников в группы
class report_poll_theme_personals extends report_personals
{
 var $title='Участники темы опроса' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $rec_event=array() ;
 var $theme_id=0 ;
 var $ids=0 ;
 var $status=0 ;

  function create_usl_select_obj_local(&$usl)
  { $_usl_join=[] ;
    // таблица статусов участий в мероприятии
    //$this->left_join['event_pass']['join']='left join obj_site_events_pass as pass on pass.personal_id=fl.pkey and pass.event_id='.$this->event_id ;

    // учет условий отбора сотрудников в темах
    $arr_themes_viewers=execSQL_row('select pkey,obj_name from personals_filter where obj_name like "view_personals_poll_section%"') ;
    if (_sizeof($arr_themes_viewers)) foreach($arr_themes_viewers as $id=>$viewer_name)
    { $this->left_join['poll_section_'.$id]['join']='left join '.$viewer_name.' as tv'.$id.' on tv'.$id.'.pkey=fl.pkey' ;
      $_usl_join[]='not  tv'.$id.'.pkey is null' ;
    }
    if (_sizeof($_usl_join)) $usl[]='('.implode(" or ",$_usl_join).')' ;

    // учет собственный условий отбора мероприятия
    //if ($this->event_id) $this->rec_event=EVENTS()->get_event_by_id($this->event_id) ;
    /*if ($this->rec_event['pkey'] and $this->rec_event['_ext_info']['local_usl_select'])
    {
      $viewer_name=execSQL_value('select obj_name from personals_filter where reffer="'.$this->rec_event['_reffer'].'"') ;
      if ($viewer_name)
        { $id=$this->rec_event['pkey'] ;
          $this->left_join['poll_event_'.$this->rec_event['pkey']]['join']='left join '.$viewer_name.' as te'.$this->rec_event['pkey'].' on te'.$this->rec_event['pkey'].'.pkey=fl.pkey' ;
          $this->left_join['poll_event_'.$this->rec_event['pkey']]['usl']='not  te'.$id.'.pkey is null' ;
        }
      //damp_array($this->rec_event);
	}*/

    // отбор участников по статусу
    if ($this->status==1)         $usl[]='(pass.status=1 or pass.status is null)' ;
    else  if ($this->status==2)   $usl[]='pass.status=2' ;
    else  if ($this->status==3)   $usl[]='pass.status=3' ;


/*    $this->arr_local_select_fields=['pass.pkey as pass_id',
                                    'pass.c_data as pass_status_change_data',
                                    'pass.status as pass_status'
                                    ] ;
*/
  }

// шаблон - вывод ссылками без разделитея
  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>pass ID</th>
            <th>ID</th>
            <th>ФИО, дата рождения, Возраст</th>
            <th>Организация, подразделение</th>
            <th>Статус участия в опросе</th>
            <th>Дата доведения</th>
            <th>Операции</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   ?><tr class=item>
                <td><a href="/window/events/event_pass/<?echo $rec['pass_id']?>/" class="new_window"><?echo $rec['pass_id']?></a></td>
                <td><a href="<?echo $rec['pkey']?>" class="new_window"><?echo $rec['pkey']?></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['uid']) echo '<br><span class="nowrap small">'.$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'] ;
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec['_org_name'].'</strong><br><div class="small">'.$rec['_otdel_name'].'</div>'._IL('IL_works')->recs[$rec['working']]['obj_name']?></td>
                <td><?if ($rec['pass_status']) echo $event_obj->arr_status[$rec['pass_status']]?></td>
                <td><?if ($rec['pass_status_change_data']) date('d.m.Y H:i',$rec['pass_status_change_data'])?></td>
                <td><button class="v2" cmd="poll/exec_poll" theme_id="<?echo $this->theme_id?>" personal_id="<?echo $rec['pkey']?>">Провести опрос</button></td>

            </tr><?
        }
      ?></table><?
  }
}
