<?php
include_once(_DIR_EXT."/events_docs/i_event_docs.php");
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_events_docs_card extends c_page
{
  public $h1='Карточка мероприятия' ;
  var $rec_event ;
  var $obj_event ;
  var $rec_theme ;

 function select_obj_info()
 { if (_CUR_ID)
   { $this->rec_event=EVENTS()->get_event_by_id(_CUR_ID) ;
     if ($this->rec_event['pkey'])
     { $this->obj_event=EVENTS()->get_event_obj_by_ext($this->rec_event['ext']) ;
       $this->obj_event->rec_event=$this->rec_event ;
       $this->h1=$this->obj_event->name.' "'.$this->rec_event['obj_name'].'"' ;
     }
     if (!$this->rec_event['pkey']) $this->result=404 ;
   } else $this->result=404 ;

 }


 function menu_config()
 { if ($this->no_event_menu) { parent::menu_config() ; return ; }

   //$ids=execSQL_line('select event_pass_id from view_event_personals_docs where event_id='.$this->rec_event['pkey'].' and event_status in (2,3) and ((mess_block_from>0 and mess_block_from<'.time().') or (mess_max_data>0 and mess_max_data<'.time().'))') ;
   $ids=execSQL_line('select event_pass_id from view_event_personals_docs where event_id='.$this->rec_event['pkey'].' and event_status in (2,3) and mess_block_from>0 and mess_block_from<'.time().'') ;
   if (_sizeof($ids)) execSQL_update('update obj_site_events_pass set status=4 where event_id='.$this->rec_event['pkey'].' and pkey in ('.implode(',',$ids).')') ;

   // вкладки для сотрудника
   $arr_cnt=EVENTS()->get_event_personals_status($this->rec_event['pkey']) ;
   //damp_array($arr_cnt,1,-1);
   $arr_cnt[2]=$arr_cnt[2]+$arr_cnt[3];
   if ($this->rec_event['pkey'] and $this->rec_event['enabled'])
      { $this->menu[$this->rec_event['__href']]='Карточка мероприятия' ;
        $this->menu[$this->rec_event['__href'].'edit/step1/']='Редактировать' ;
        $this->menu[$this->rec_event['__href'].'personals/put/']=array('title'=>'Документы выданы','info_value'=>(($arr_cnt[2])? '<span>'.$arr_cnt[2].'</span>':'')) ;
        $this->menu[$this->rec_event['__href'].'personals/block/']=array('title'=>'Сдача просрочена','info_value'=>(($arr_cnt[4])? '<span>'.$arr_cnt[4].'</span>':'')) ;
        $this->menu[$this->rec_event['__href'].'personals/get/']=array('title'=>'Документы сданы','_info_value'=>(($arr_cnt[5])? '<span>'.$arr_cnt[5].'</span>':'')) ;

        $this->menu[$this->rec_event['__href'].'personals/']='Все участники' ;
        //$this->menu[$this->rec_event['__href'].'log/']='История' ;
        $this->menu[$this->rec_event['__href'].'db/']='Исходные данные' ;
        $this->page_type='window' ;
      }
   elseif ($this->rec_event['pkey'])
      { $this->menu[$this->rec_event['__href'].'edit/step1/']='Параметры мероприятия' ;
        $this->page_type='window' ;
      }
   else parent::menu_config() ;
 }


 function block_main()
 { $this->page_title() ;

   //damp_array($this->rec_event) ;
   //damp_array($this->obj_event) ;
   $this->obj_event->panel_event_info();
   /* кнопка не нужна, использоваваль для перехода на мероприятие для учета документов выданных ранее
    * ?><div class="sky-form no_box_shadow"><button class="button v2" cmd="events/update_personal_status" event_id="<?echo $this->rec_event['pkey']?>">Обновить список подлежащих мероприятию</button><div class="clear"></div></div><?*/
   ?><br><?
   /////PERSONAL()->update_message_status() ;
   $this->panel_stats_by_org() ;
 }

 function panel_stats_by_org()
 { ?><h2>Статистика прохождения по организациям:</h2><?
   include_once(_DIR_EXT.'/events_docs/report_event_docs_info_by_orgs.php') ;
   $report_obj=new report_event_docs_info_by_orgs() ;
   $report_obj->event_id=$this->rec_event['pkey'] ;
   $report_obj->usl_select_event_pass='event_status>1' ;
   $report_obj->filter['group_id']=MEMBER()->cur_group_id ;
   //$report_obj->setting() ;
   $report_obj->view() ;
 }

  function panel_events_themes()
  { ?><div id="panel_events_themes"><h2>Темы инструктажа:</h2><?
      $recs_docs_by_themes=array() ;
      $recs_themes=execSQL('select * from obj_site_events_themes where parent='.$this->rec_event['pkey'].' and clss=225 order by indx') ;
      if (_sizeof($recs_themes))
       { $recs_docs=execSQL('select pkey,parent,obj_name,file_name from obj_site_events_themes_files where parent in ('.implode(',',array_keys($recs_themes)).')',0,1) ;
         $recs_docs_by_themes=group_by_field('parent',$recs_docs) ;
       }

       ?><table class="basic fz_small full auto"><tr class="head"><th>№</th><th>Наименование</th><th>Длительность, мин.</th><th>Методические материалы</th></tr><?
           if (_sizeof($recs_themes)) foreach($recs_themes as $rec)
           { ?><tr>
                 <td style="width:10%;" class="indx center"><?echo $rec['indx']?></td>
                 <td style="width:35%;" class="left"><?echo $rec['obj_name']?></td>
                 <td style="width:5%;" class="center"><?echo $rec['length']?> мин.</td>
                 <td style="width:20%;text-align:left;"><?
                 if (_sizeof($recs_docs_by_themes[$rec['pkey']]))
                 {  ?><ul><?
                    foreach($recs_docs_by_themes[$rec['pkey']] as $rec_doc) {?><li><a href="<?echo _MAIN_PROTOCOL._MAIN_DOMAIN?>/public/instruktions_docs/<?echo $rec_doc['file_name']?>" class="new_window"><?echo $rec_doc['obj_name']?></a></li><?}
                    ?></ul><?
                 }
                 ?></td>
               </tr>
             <?
           }
           ?>
            </table>
            <style type="text/css">
               table.basic td.indx{text-align:center;}
               table.basic td.indx:hover i{display:inline;cursor:pointer;}
               table.basic ul{margin:0 0 0 20px;;padding:0;}
               table.basic ul li{padding:0;margin:0;}
            </style>
            </div>
           <?
  }

  function panel_personal_info()
    {   // данные по участникам мероприятия с учетом группы текущего аккаунта
        $arr_personals_status=EVENTS()->get_event_personals_status($this->rec_event['pkey']) ;
        $personals_count=array_sum($arr_personals_status) ;

        ?><div class="row event_info">
            <section class="col col-3">
                   <label class="label">Условие отбора участников</label>
                   <?echo strip_tags($this->rec_event['_ext_info']['info_filter'])?>
            </section>
            <section class="col col-3">
                   <label class="label">Сотрудники</label>
                   <strong><?echo $personals_count.' '.get_case_by_count_1_2_5($personals_count,'сотрудник,сотрудника,сотрудников')?></strong>
            </section>
 	  </div><?
    }




}



?>
