<?php
include_once(_DIR_TO_MODULES.'/personal/i_XLS_import.php') ;
class i_upload_persons
{
  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='' ;

  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' ;
  }


  function exec()
  { ?><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')) ;

    XLS_import()->connect_SOURCE('members_'.$this->session_uid.'.xls') ;
    XLS_import()->read_only=$this->read_only ;
    XLS_import()->full_update=$this->full_update ;
    XLS_import()->parse_XLS_headers() ;
    XLS_import()->create_temp_tables() ;
    XLS_import()->parse_SOURCE_to_DB() ;
    if (!$this->read_only)
    {   XLS_import()->sync_TEMP_DB_ESMO() ;
        XLS_import()->sync_workings_persons() ;
                }
                else
    {   ?><h2>Таблица-источник физических лиц</h2><?
        $recs=execSQL('select * from '.XLS_import()->table_fz);
        print_2x_arr($recs) ;
        ?><h2>Таблица-источник сотрудников организаций</h2><?
        $recs=execSQL('select * from '.XLS_import()->table_so);
        print_2x_arr($recs) ;
               }

    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('data'=>$res)) ;
            }
}



?>