<?php
include_once("c_esmo_magnit_pmo_card_edit_step1.php");
class c_page_cab_esmo_magnit_pmo_card_edit_step4 extends c_page_cab_esmo_magnit_pmo_card_edit_step1
{
  public $h1='Редактирование параметров ПМО - срок действия ПМО' ;

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

  function panel_setup_PMO_len()
  {   $this->form_open() ;
      ?>
        <table class="basic fz_small full auto">
            <tr>
                <th>Выбор</th>
                <th>Срок действия ПМО</th>
                <th>Основание выбора срока ПМО</th>
                <th>Число сотрудников</th>
            </tr>
            <tr>
                <td></td>
                <td><?$this->form->select(['name'=>'pmo_len_def','recs'=>EVENT_PMO()->arr_pmo_len,'value'=>$this->rec_event['_ext_info']['pmo_len'],'style'=>'_width:150px;text-align:center;float:none;display:inline;']);?></td>
                <td class="left">значение по умолчанию для всех участников ПМО</td>
                <td><? $cnt=execSQL_value('select count(*) from '.$this->rec_event['viewer_name'].' ') ;
                       echo $cnt ;
                    ?></td>
            </tr>
            <tr>
                <td><input type="hidden" name="_check_vpf" value="0">
                    <input type="checkbox" name="_check_vpf" value="1" <?if ($this->rec_event['_ext_info']['pmo_len_union']['use_vpf']) echo 'checked=1'?></td>
                <td>в настройках ВФП</td>
                <td class="left">на основнии ВПФ по ИНРМ сотрудника</td>
                <td><? $cnt=execSQL_value('select count(distinct(personal_id)) from obj_site_workers where inrm!=""') ;
                      echo $cnt ;
                    ?></td>
            </tr>
            <tr>
            </tr><?
              if (_sizeof(_IL('IL_group_medic')->recs)) foreach(_IL('IL_group_medic')->recs as $rec) //if (stripos($rec['obj_name'],'ГБ')!==false)
              {  //$arr=get_arr_links_to_reffer($rec['_reffer']) ;
                  $cnt_work=0 ; $cnt_pers=0 ;
                 //if (_sizeof($arr)) foreach($arr as $rec_link) if ($rec_link['link_clss']==211) $cnt_pers++ ;
                 if ($rec['id']) $cnt_pers=execSQL_value('select count(pkey) from view_personals_medic_group_'.$rec['id'].' where enabled=1 and clss=211') ;
                 //damp_array($arr,1,-1) ;
                  $pmo_len_value=(isset($this->rec_event['_ext_info']['pmo_len_union']['use_gb'][$rec['id']]))? $this->rec_event['_ext_info']['pmo_len_union']['use_gb'][$rec['id']]:1 ;
                  ?><tr class=item>
                      <td><input type="hidden" name="_check_gb[<?echo $rec['id']?>]" value="0">
                          <input type="checkbox" name="_check_gb[<?echo $rec['id']?>]" value="1" <?if ($this->rec_event['_ext_info']['pmo_len_union']['use_gb'][$rec['id']]) echo 'checked=1'?>>
                      </td>
                      <td class="center"><?$this->form->select(['name'=>'pmo_len['.$rec['id'].']','recs'=>EVENT_PMO()->arr_pmo_len,'value'=>$pmo_len_value,'style'=>'_width:50px;text-align:center;float:none;display:inline;']);?></td>

                      <td class="left"><?echo $rec['obj_name']?></td>
                      <td><? echo ($cnt_pers)? $cnt_pers:'-'?></td>
                  </tr><?
              }

        ?>

        </table><br><?
      $this->button('Сохранить','save_pmo_len_info',array('cmd_method'=>'v1','cmd'=>'save_pmo_len_info','title'=>'Сохранить')) ;
      $this->form_close() ;
  }


  function CMD_save_pmo_len_info()
  {   //damp_array($_POST);
      $data=[] ;
      if ($_POST['filter']['pmo_len_def']) $data['pmo_len']=$_POST['filter']['pmo_len_def'] ; // исправить, pmo_len_def должны быть сразу в POST
      if (isset($_POST['_check_vpf'])) $data['pmo_len_union']['use_vpf']=$_POST['_check_vpf'] ;
      if (_sizeof($_POST['_check_gb'])) foreach($_POST['_check_gb'] as $gb_id=>$use) if ($use) $data['pmo_len_union']['use_gb'][$gb_id]=$_POST['pmo_len'][$gb_id] ;
      //damp_array($data,1,-1);
      EVENTS()->save_events($this->rec_event['pkey'],$data) ;
      $this->select_obj_info() ;
      //damp_array($this->rec_event['_ext_info']['pmo_len_union']);
  }

  function _CMD_save_event()
  { //damp_array($_POST) ;
    EVENTS()->save_events($this->rec_event['pkey'],$_POST['filter']) ;
    if (!$this->rec_event['enabled']) redirect_301_to($this->rec_event['__href'].'/personals/free/') ;
    else $this->rec_event=EVENTS()->get_event_by_id($this->rec_event['pkey']) ;
  }



}
?>
