<?php
// /services/SOAP/
include_once(_DIR_EXT.'/HTML/c_page_TXT.php') ;
include_once(_DIR_EXT.'/esmo_gateway/i_SOAP_import.php') ;
class c_SOAP extends c_page_txt
{
  var $read_only=0 ;
  var $full_update=0 ;
  var $arr_exsist_ids=array() ;
  var $session_uid='' ;
  var $log_fname='' ;
  var $log_bash='' ;
  var $page_output='' ;
  var $action='' ;
  
  function __construct($options=array())
  { $this->session_uid=($options['uid'])? $options['uid']:$_GET['uid'] ;
    $this->read_only=($options['read_only'])? $options['read_only']:$_GET['read_only'] ;
    $this->full_update=($options['full_update'])? $options['full_update']:$_GET['full_update'] ;
    $this->log_fname=FILE_LOG($this->session_uid)->log_fname ;
    $this->page_output='/temp/result_page_'.$this->session_uid.'.html' ;
    $this->log_bash='/temp/log_bash_'.$this->session_uid.'.txt' ;

    $this->action=$_GET['action'] ;
    $this->full_update=$_GET['full_update'] ;
  }


  function body()
  { ?><link rel="stylesheet" type="text/css" href="/<?echo _CLASS_?>/style.css" charset="utf-8"><?
    FILE_LOG()->append('READ_ONLY: '.(($this->read_only)? 'ON':'OFF')) ;
    FILE_LOG()->append('FULL_UPDATE: '.(($this->full_update)? 'YES':'NO')) ;

    if ($this->action=='import_persons' and $this->full_update)  $this->import_persons_from_SOAP_full() ;

    reboot_engine() ; FILE_LOG()->append('reboot_engine') ;
    //PERSONAL()->update_levels_parents() ; FILE_LOG()->append('update_levels_parents') ;
    FILE_LOG()->append('END') ;

    LOGS()->reg_log('upload_persons_from_xls','<a target=_blank href="'.$this->page_output.'">Отчет</a><br><a href="/temp/full_'.basename($this->log_fname).'" target=_blank>Лог загрузки</a><br><a href="'.$this->log_bash.'" target=_blank>Лог BASH</a>',array()) ;
  }

  function  import_persons_from_SOAP_full($options=array())
     {   ob_start() ;

         SOAP_import()->SOAP_node=$GLOBALS['LS_magnit_import_personal_from_SOAP_node_full'] ; //'ESMOCHG' ; // только изменения
         SOAP_import()->full_update=1 ;
         SOAP_import()->read_only=$this->read_only ;

         SOAP_import()->connect_SOURCE($options['local_fname']) ;

         if (strlen(SOAP_import()->SOAP_XML_content))
         {   FILE_LOG()->append('parse_source_headers: start') ;
         SOAP_import()->parse_source_headers() ;
         FILE_LOG()->append('parse_source_headers: end') ;

         FILE_LOG()->append('create_temp_tables: start') ;
         SOAP_import()->create_temp_tables() ;
         FILE_LOG()->append('create_temp_tables: end') ;

         FILE_LOG()->append('parse_SOURCE_to_DB: start') ;
         SOAP_import()->parse_SOURCE_to_DB() ;
         FILE_LOG()->append('parse_SOURCE_to_DB: end') ;

             FILE_LOG()->append('update_levels_parents PERSONAL: start') ;
             PERSONAL()->update_levels_parents() ;
             FILE_LOG()->append('update_levels_parents PERSONAL: start') ;

         FILE_LOG()->append('sync_TEMP_DB_ESMO: start') ;
         SOAP_import()->sync_TEMP_DB_ESMO() ;
         FILE_LOG()->append('sync_TEMP_DB_ESMO: end') ;

         FILE_LOG()->append('sync_workings_persons: start') ;
         SOAP_import()->sync_workings_persons() ;
         FILE_LOG()->append('sync_workings_persons: end') ;
         }
         $text=ob_get_clean() ;
         echo $text ;
         $log_fname=LOGS()->reg_file_log('check_import_persons_from_SOAP_update',$text) ;
         LOGS()->reg_log('import_personal_from_xml','Загрузка данных XML c узла '.SOAP_import()->SOAP_node.'<br><a href="/logs/'.str_replace(array('[fname=',']'),'',basename($log_fname)).'" target=_blank>Отчет</a><br>') ;

     }
}



?>