<?php
//include_once("c_esmo_gateway_upload.php");
include_once("c_ot.php");
//include_once(_DIR_TO_ENGINE.'/admin/i_admin_system.php') ;
class c_page_cab_ot_working_vpf extends c_page_cab_ot
{
 public $h1='Задание ВПФ' ;
 public $objPHPExcel ;
 public $aSheet ;
 public $csv_headers ;
 public $db_headers ;
 public $setting ;
 public $table_name ;
 public $setting_name ;

  public $page_type='window' ;
  public $rec_mo=array() ;
  public $rec_personal=array() ;
  public $docs=array() ;
  public $inrm=0 ;
  public $cnt_docs=0 ;

  function select_obj_info()
    { if (_CUR_ID)
       { //$this->rec_mo=KT()->get_mo_by_id(_CUR_ID) ;
         //if ($this->rec_mo['pkey'])
         //{ if ($this->rec_mo['member_id']) $this->rec_personal=PERSONAL()->get_personal_by_id($this->rec_mo['member_id']) ;
         //}
         //else $this->result=404 ;
       }
      $this->inrm=$this->filter['org_id'].'.'.$this->filter['otdel_id'].'.'.$this->filter['working_id']  ;
      $this->cnt_docs=execSQL_value('select count(pkey) from files where obj_reffer="'.$this->inrm.'"') ;
    }


    function menu_config()
     { // вкладки для сотрудника
       if ($this->rec_mo['pkey'])
          { $this->menu[$this->rec_mo['__href']]='Карточка КТ' ;
            if ($this->rec_personal['pkey']) $this->menu[$this->rec_personal['__href'].'?from_kt='.$this->rec_mo['pkey']]='Карточка сотрудника' ;
            if ($this->rec_personal['pkey']) $this->menu[$this->rec_personal['__href'].'card/?from_kt='.$this->rec_mo['pkey']]='Медицинская карточка' ;
            $this->menu[$this->rec_mo['__href'].'db/']='Исходные данные' ;
          }
     }

     function second_menu_config()
      { //if ($this->rec_mo['pkey'])
        { $this->second_menu['/cab/ot/working_vpf/[org_id='.$this->filter['org_id'].',otdel_id='.$this->filter['otdel_id'].',working_id='.$this->filter['working_id'].']/']='Классы условий труда' ;
          $this->second_menu['/cab/ot/working_vpf/[org_id='.$this->filter['org_id'].',otdel_id='.$this->filter['otdel_id'].',working_id='.$this->filter['working_id'].']/edit/']='ВПФ' ;
          $this->second_menu['/cab/ot/working_vpf/[org_id='.$this->filter['org_id'].',otdel_id='.$this->filter['otdel_id'].',working_id='.$this->filter['working_id'].']/doctor/']='ПМО' ;
          if ($this->cnt_docs) $this->second_menu['/cab/ot/working_vpf/[org_id='.$this->filter['org_id'].',otdel_id='.$this->filter['otdel_id'].',working_id='.$this->filter['working_id'].']/docs/']='Загруженные документы' ;
          $this->second_menu['/cab/ot/working_vpf/[org_id='.$this->filter['org_id'].',otdel_id='.$this->filter['otdel_id'].',working_id='.$this->filter['working_id'].']/upload_docs/']='Загрузка документа' ;

        }
      }



 function block_main()
 {
    $this->panel_filter_info() ;
    $this->get_panel_setting_vpf_ball() ;
 }

 function panel_filter_info()
 {
     $org_name=PERSONAL()->get_org_names_by_ids($this->filter['org_id']) ;
     $otdel_name=PERSONAL()->get_org_names_by_ids($this->filter['otdel_id']) ;
     $work_name=execSQL_value('select obj_name from list_workings where pkey='.$this->filter['working_id']) ;

     ?>Организация: <strong><?echo $org_name?></strong><br>
       Подразделение: <strong><?echo $otdel_name?></strong><br>
       Должность: <strong><?echo $work_name?></strong><br>
       Индивидуальный номер рабочего места: <strong><?echo $this->inrm?></strong><br><?
 }

    function get_panel_setting_vpf_ball()
      {   $level2=execSQL('select pkey,concat(number," ",obj_name) as name,level,parent1,parent2,parent3,parent4 from list_vpf where clss=233 and level in (2,3,4) order by number ') ;
          $_usl=array() ;
          $_usl[]='t1.clss=232' ;
          $_usl[]='t3.clss=230' ;
          if ($this->filter['org_id']) $_usl[]='org_id='.$this->filter['org_id'] ;
          if ($this->filter['otdel_id']) $_usl[]='otdel_id='.$this->filter['otdel_id'] ;
          if ($this->filter['working_id']) $_usl[]='work_id='.$this->filter['working_id'] ;
          $usl=implode(' and ',$_usl) ;
          $recs=execSQL('select t1.*,
                       t4.obj_name as org_name, 
                       t5.obj_name as otdel_name, 
                       t2.obj_name as work_name, 
                       t3.number as vpf_number,t3.obj_name as vpf_name,t3.parent2 as vpf_parent2,t3.parent3 as vpf_parent3,t3.parent4 as vpf_parent4 
                       from list_workings_fvp t1
                       left join list_workings t2 on t2.pkey=t1.work_id 
                       left join list_vpf t3 on t3.pkey=t1.vpf_id 
                       left join obj_site_personals t4 on t4.pkey=t1.org_id 
                       left join obj_site_personals t5 on t5.pkey=t1.otdel_id 
                       where '.$usl.'
                       order by vpf_number
                       ',0) ;
          $cur_section2=0 ;$cur_section3=0 ;$cur_section4=0 ;
          ?><div id="panel_select_item_vpf"><table class="basic full auto" id="table_ball_select"><?
          if (_sizeof($recs)) foreach($recs as $rec)
          {   if ($rec['vpf_parent2'] and (!$cur_section2 or $rec['vpf_parent2']!=$cur_section2))  {?><tr><th colspan="3" style="text-align:left;"><?echo $level2[$rec['vpf_parent2']]['name']?></th></tr><? $cur_section2=$rec['vpf_parent2'];}
              if ($rec['vpf_parent3'] and (!$cur_section3 or $rec['vpf_parent3']!=$cur_section3))  {?><tr><th colspan="3" style="text-align:left;"><?echo $level2[$rec['vpf_parent3']]['name']?></th></tr><? $cur_section3=$rec['vpf_parent3'];}
              if ($rec['vpf_parent4'] and (!$cur_section4 or $rec['vpf_parent4']!=$cur_section4))  {?><tr><th colspan="3" style="text-align:left;"><?echo $level2[$rec['vpf_parent4']]['name']?></th></tr><? $cur_section4=$rec['vpf_parent4'];}
              $ball= ($rec['ball'])? $rec['ball']:0 ;
              if ($ball)
              { $t=$ball-(int)$ball ;
                if (!$t) $ball=(int)$ball ;
              }
              ?><tr>
                <td class="left nowrap"><?echo $rec['vpf_number']?></td>
                <td class="left"><?echo $rec['vpf_name']?></td>
                <td class="center vpf_ball" vpf_pkey="<?echo $rec['pkey']?>" style="width:150px;"><?echo $ball?></td>
              </tr><?

          }
          ?></table></div>
          <?



      }

}



?>
