<?php
//include_once(_DIR_EXT.'/HTML/c_page_XML.php') ;
include_once(_DIR_EXT.'/HTML/c_page_TXT.php') ;
//class c_services_pl_get_med_orgs extends c_page_XML
class c_services_pl_get_med_director extends c_page_txt
{

	function check_access()
  { if (!$this->setting['no_check_access']) $result=ESMO_GATEWAY()->api_check_access() ;
    else $result=['status'=>'success','comment'=>''] ;

    //if ($result['client_id']) $this->client_id=$result['client_id'] ;
		if ($result['status']!='success') { $this->response_error($mode,array('code'=>$result['comment'],'ip'=>$_SERVER['REMOTE_ADDR'])) ; }

		$result=['status'=>'success','comment'=>''] ;
    return($result) ;
  }

  function body()
  {
     $result=ESMO_GATEWAY()->api_check_access() ;
     if ($result['status']!='success') { $this->response_error(array('code'=>$result['comment'],'ip'=>$_SERVER['REMOTE_ADDR'],'token'=>$result['token']));  return ; }

		 $t1=fixed_time() ;
		 ob_start() ;
     $options=array() ;
     if (isset($_GET['limit'])) $options['limit']=$_GET['limit'] ;

		 include_once(_DIR_EXT.'/pl/report_med_directors.php') ;
		 $report_obj=new report_med_directors() ;
     $report_obj->filter=$_GET;
     $report_obj->view_as_XML($options) ;


		$text_out=ob_get_clean() ;

		 $headers=getallheaders() ;
		 $send_token=(str_replace('Token ','',$headers['Authorization']))?:'' ;
		 //ENGINE()->save_temp_setting()
		 //include_once(_DIR_TO_MODULES.'/pl/i_pl_req_log.php') ;
		 //\esmo\pl\i_pl_req_log::create(['ip'=>$_SERVER['remote_addr']])
		 $t2=fixed_time($t1) ;
		 LOGS()->log_request($_SERVER['REMOTE_ADDR'],$_SERVER['SERVER_ADDR'],'pl/get_med_orgs','',$text_out,array
		            ('api_key'=>($send_token)? 1:0, // ставим флаг авторизации по api-key
		             'size1'=>0,
		             'size2'=>mb_strlen($text),
		             'time_exec'=>$t2,
		             //'request_UID'=>$this->request_UID,
		             //'request_debug'=>$debug,
		             'req_type'=>0,
		             //'temp'=>$temp,
		             //'req_url'=>$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI']
		             'req_url'=>$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_ADDR'].$_SERVER['REQUEST_URI'],
								 'content_type1'=>'post',
								 'content_type2'=>'xml',
		        )) ;

		 echo $text_out ;
  }

  function response_error($arr)
  {  header("Content-type: text/xml;charset=UTF-8") ;
	   $imp = new DOMImplementation; // Creates an instance of the DOMImplementation class
	   $xml_doc = $imp->createDocument("",""); // Creates a DOMDocument instance
		 $xml_doc->encoding = 'utf-8';
		 $xml_doc->formatOutput = true;
		 $xml = add_element($xml_doc,$xml_doc,'error','',array('date'=>date('Y-m-d H:i'))) ;
		 if (_sizeof($arr)) foreach($arr as $name=>$value) add_element($xml_doc,$xml,$name,$value) ;
		 echo $xml_doc->saveXML() ;
  }

}



?>
