<?php
include_once(_DIR_EXT.'/HTML/c_page_TXT.php') ;
class c_services_faceid_photo extends c_page_txt
{
  function body()
  { $rec_photo=execSQL_van('select * from obj_site_personals_image where pkey='._CUR_ID) ;
    $rec_personal=PERSONAL()->get_personal_by_id($rec_photo['parent']) ;

  	if (!$_GET['result'])
    { $cont=(file_exists($rec_personal['_image_dir']))? file_get_contents($rec_personal['_image_dir']):null ;

	  header('Content-Type: application/force-download');
	  header('Content-Length: '.strlen($cont));
	  header ("Accept-Ranges: bytes");
	  header('Content-disposition: inline; filename="'.basename($rec_personal['_image_dir']).'"');

	  echo $cont ;
	  FACEID()->reg_log($rec_personal['pkey'],$rec_photo['pkey']) ;
    }
    else
    {   $last_log_id=execSQL_value('select max(pkey) from log_faceid_upload_photo where personal_id='.$rec_personal['pkey'].' and image_id='.$rec_photo['pkey']) ;
    	$data=array('time_response'=>time()) ;

	    if ($_GET['result']=='ok')
	    { execSQL_update('update obj_site_personals_image set faceimg=1 where pkey='._CUR_ID) ;
	      $data['result']=1 ;
	    }
	    else
	    { $data['result']=2 ;
		  $data['comment']=$_GET['message'] ;
	    }

	    FACEID()->update_log($last_log_id,$data) ;

	    echo 'ok' ;
    }



  }
}
?>