<?php
include_once(_DIR_EXT.'/HTML/c_page_TXT.php') ;
class c_services_docs_upload_scan_json extends c_page_TXT
{ public $terminal_id ;
  public $personal_id ;
  public $mo_id ;

  function c_page_json() {}
  function body()
  { $res=array() ; ob_start() ;
    if (_sizeof($_FILES)) $res=$this->upload_doc() ;
    $res['report']=ob_get_clean() ;
    $text_json_out=json_encode($res,JSON_UNESCAPED_UNICODE) ;
    echo $text_json_out ;
  }

  function upload_doc()
  {   $result=array() ;
      if (_sizeof($_FILES))
       { foreach($_FILES as $file_info)
           {   $abs_upload_fname=DOCS()->upload_scan($file_info['tmp_name'],$file_info['name']) ;

               if ($file_info['type']=='application/pdf') DOCS()->convert_PDF_to_JPG2($abs_upload_fname,$result) ;
               else $result['file_name'][]=$abs_upload_fname  ;

               // регистрируем скан в таблице сканов
               if (_sizeof($result['file_name'])) foreach($result['file_name'] as $abs_upload_fname) DOCS()->register_file_scan($abs_upload_fname) ;

           }
           $result['status']='ok'  ;
       }
       else $result['status']='error'  ;
       return($result) ;
    }



}
