<?php
include_once('c_score_settings.php') ;
class c_page_cab_score_actions extends c_page_cab_score_settings
{
 public $h1='Фрамингемская шкала - инициализация данных' ;

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

     ?> <button class="v1" cmd="clear_score">Сбросить значения SCORE</button>
           <button class="v1" cmd="clear_frs">Сбросить значения FRS</button>
           <button class="v1" cmd="clear_smoking">Сбросить курение, холестерин</button>
           <button class="v1" cmd="random_smoking">RAND() курение, холестерин</button>
           <button class="v1" cmd="full_score">Заполнить значения SCORE</button>
           <button class="v1" cmd="full_frs">Заполнить значения FRS</button>
           <br><br>
          <?
          $cmd=$_POST['cmd'] ;
          if ($cmd and method_exists($this,$cmd)) $this->$cmd() ;
 }

 function clear_score()
 {
     execSQL_update('update obj_site_mo_session set score=-1',2) ;
 }

 function clear_frs()
 {
     execSQL_update('update obj_site_mo_session set frs=-1',2) ;
 }

 function random_smoking()
 {   execSQL_update('update obj_site_personals set hol=RAND()*10 where clss=211',2) ;
     execSQL_update('update obj_site_personals set smoking=ROUND(RAND(),0) where clss=211',2) ;
     execSQL_update('update obj_site_personals set lek=ROUND(RAND(),0) where clss=211',2) ;
 }

 function clear_smoking()
 {   execSQL_update('update obj_site_personals set hol=0',2) ;
     execSQL_update('update obj_site_personals set smoking=0 where clss=211',2) ;
     execSQL_update('update obj_site_personals set lek=0 where clss=211',2) ;
     $this->update_personals_age() ;
 }
    
  function full_frs()
  {   ///include_once(_DIR_EXT.'/score/i_framingham.php') ;
      $obj=new i_framingham() ;
      $cnt=$obj->update_frs_in_mo() ;
      $recs=execSQL('select pkey,frs from obj_site_mo_session where frs>=0  order by pkey desc limit 100',2) ;
      if ($cnt){?>?><script type="text/javascript">document.location.reload();</script><?}
  }    
    
  function full_score()
  {   //include_once(_DIR_EXT.'/score/i_score.php') ;
      $obj=new i_score() ;
      $cnt=$obj->update_score_in_mo() ;
      $recs=execSQL('select pkey,frs from obj_site_mo_session where frs>=0  order by pkey desc limit 100',2) ;
      if ($cnt){?><script type="text/javascript">document.location.reload();</script><?}
  }
    
    function update_personals_age()
   	    {
   	      $recs=execSQL_row('select pkey,dr from obj_site_personals') ;
   	      if (_sizeof($recs)) foreach($recs as $id=>$dr)
   	      {  $age=ENGINE()->get_age_by_dr($dr) ;
   	         update_rec_in_table('obj_site_personals',array('age'=>$age),'pkey='.$id,array('debug'=>0)) ;
   	      }
   	      echo 'Обновлены даты рождения, '._sizeof($recs).' сотрудников<br>' ;
   	    }    
}
?>
