<?php
class report_master_opo_info extends c_report
{
 var $title='Статистика прохождения ОПО' ;
 var $view_by_space_filter=1 ;
 var $event_id=0 ;

// шаблон - вывод ссылками без разделитея
  function HTML_report_body($options=array())
  { $usl=array() ;
    $usl[]='pass.event_id='.$GLOBALS['LS_esmo_OPO_event'] ;
    $usl[]='pass.enabled=1' ;
    $usl[]='not tp.pkey is null' ;
    $usl_select=implode(' and ',$usl) ;
    $list_recs=execSQL('select fl.parent1,fl.parent2,fl.parent3,fl.parent4,fl.parent5,fl.parent6,fl.parent7,fl.parent8,fl.parent9,pass.status,count(personal_id) as cnt_person 
                    from obj_site_events_pass pass 
                    left join obj_site_personals fl on fl.pkey=pass.personal_id
                    left join '.MEMBER()->personal_viewer_name.' tp on tp.pkey=pass.personal_id
                    where '.$usl_select.'
                    group by fl.parent1,fl.parent2,fl.parent3,fl.parent4,fl.parent5,fl.parent6,fl.parent7,fl.parent8,fl.parent9,pass.status 
                    order by fl.parent1,fl.parent2,fl.parent3,fl.parent4,fl.parent5,fl.parent6,fl.parent7,fl.parent8,fl.parent9,pass.status ',0,1) ;

    PERSONAL()->full_org_othdels_work_names($list_recs) ;
    //print_2x_arr($list_recs);

    $list_recs2=[] ; $arr_org_names=[] ;
    if (_sizeof($list_recs)) foreach($list_recs as $rec)
    {  $arr_org_names[$rec['parent2']]=$rec['_parent2_name'] ;
       $list_recs2[$rec['parent2']][$rec['_dep_id']]['_otdel_path']=$rec['_otdel_path'] ;
       $list_recs2[$rec['parent2']][$rec['_dep_id']]['arr_status'][$rec['status']]=$rec['cnt_person'] ;
    }

        ?><table class="basic fz_small full auto">
            <tr>
               <th>Организация</th>
               <th>Подразделение</th>
               <th>Подлежит ОПО</th>
               <th>Заблокирован по прохождению ОПО</th>
               <th>ОПО пройден, годен</th>
               <th>ОПО пройден, не годен</th>
            </tr>
            <?if ($list_recs2) foreach($list_recs2 as $org_id=>$recs_deps)
                {  echo '<tr>' ;
                   ?><td class="left" <?if (_sizeof($recs_deps)>1) {echo 'rowspan='._sizeof($recs_deps);} ?>>
                        <?echo $arr_org_names[$org_id]?>
                    </td>
                      <? $i=0 ;
                          if (_sizeof($recs_deps)) foreach($recs_deps as $dep_id=>$dep_info)
                          { if ($i) echo '<tr>' ;
                            $arrs=$dep_info['arr_status'] ;
                            $cnt_pass=$arrs[1]+$arrs[2]+$arrs[22]+$arrs[3]+$arrs[4]+$arrs[6] ;
                            $cnt_block=$arrs[5]+$arrs[7] ;
                            $cnt_success=$arrs[8] ;
                            $cnt_failed=$arrs[9] ;
                             ?><td class="left" ><?echo $dep_info['_otdel_path']?></td>
                              <td><?echo ($cnt_pass)? '<span class="link v2" cmd="esmo_master/show_opo_personals" status="pass" org_id='.$org_id.' dep_id="'.$dep_id.'">'.$cnt_pass.'</span>':'-'?></td>
                              <td><?echo ($cnt_block)? '<span class="link v2" cmd="esmo_master/show_opo_personals" status="block"  org_id='.$org_id.' dep_id="'.$dep_id.'">'.$cnt_block.'</span>':'-'?></td>
                              <td><?echo ($cnt_success)? '<span class="link v2" cmd="esmo_master/show_opo_personals" status="success"  org_id='.$org_id.' dep_id="'.$dep_id.'">'.$cnt_success.'</span>':'-'?></td>
                              <td><?echo ($cnt_failed)? '<span class="link v2" cmd="esmo_master/show_opo_personals" status="failed"  org_id='.$org_id.' dep_id="'.$dep_id.'">'.$cnt_failed.'</span>':'-'?></td>
                            <?
                            echo '</tr>' ;
                            $i++ ;
                          }
                 }?>
             </table>
             <style type="text/css">
                       span.link{text-decoration:underline;}
             </style>
        <?
  }



}

?>
