<?php
include_once("c_magnit_setting.php");
include_once(_DIR_TO_MODULES_LOCAL.'/magnit/i_SOAP_import.php') ;
class c_page_cab_magnit_setting_tests extends c_page_cab_magnit_setting
{
  public $h1='Магнит - Проверки' ;
  public $no_view_log=0 ;

  var $arr_cmd=array('check_import_propusk_from_skud'=>'Проверка импорта пропусков из СКУД',
                     'check_import_propusk_from_skud_RO'=>'Проверка импорта пропусков из СКУД (только чтение)',
                     'check_import_photo_from_skud'=>'Проверка импорта фото из СКУД',
                     'check_import_photo_from_skud_RO'=>'Проверка импорта фото из СКУД (только чтение)',
                     'view_SKUD_pass'=>'Просмотр буферной таблицы пропусков СКУД',
                     'view_SKUD_photo'=>'Просмотр буферной таблицы фото СКУД',
                     'view_propusk_from_skud'=>'Поиск пропусков из СКУД',
                     'check_persons'=>'Проверка данных сотрудников',
                     'check_import_persons'=>'Проверка импорта сотрудников',
                     'check_import_persons_from_SOAP_full_RO'=>'Проверка импорта сотрудников из 1С [SOAP], срез - показать источник',
                     'check_import_persons_from_SOAP_change_RO'=>'Проверка импорта сотрудников из 1С [SOAP], изменения - показать источник',
                     'check_import_persons_from_SOAP_full'=>'Проверка импорта сотрудников из 1С [SOAP], срез - загрузка',
                     'check_import_persons_from_SOAP_change'=>'Проверка импорта сотрудников из 1С [SOAP], изменения - загрузка',
                     //'check_import_persons_from_SOAP_local_view'=>'Проверка импорта сотрудников из 1С (сохраненный XML-файл)',
                     //'check_import_persons_from_SOAP_local_check'=>'Эмуляция импорта сотрудников из 1С (сгенерированный XML-файл)',
                     'show_SOAP_tables'=>'Таблицы источников',
                     'check_mails'=>'Проверка почты',
                     'show_mail_recs_in_db'=>'Таблица принятых писем',
                     'show_mail_recs_in_db_attach'=>'Таблица принятых писем - вложения',
          ) ;

 function block_main()
 { $this->page_title() ;
   //damp_array($_POST,1,-1) ;
   ?> <form action="/cab/magnit/setting/tests/">
      <select name="check_cmd"><option></option><?if (sizeof($this->arr_cmd)) foreach($this->arr_cmd as $cmd=>$title){?><option value="<?echo $cmd?>" <?if ($_POST['check_cmd']==$cmd) echo 'selected'?>><?echo $title?></option><?}?></select>
      <button class="v1" cmd="exec_check">Выполнить</button>
      <br><br></form>
  <?
     $cmd=$_POST['check_cmd'] ;
     $action=$_POST['action'] ;
     if ($cmd and method_exists($this,$cmd)) $this->$cmd() ;
     elseif ($action and method_exists($this,$action)) $this->$action() ;
     elseif ($this->filter['action'] and method_exists($this,$this->filter['action'])) $this->{$this->filter['action']}() ;

     if ($this->filter['action2'] and method_exists($this,$this->filter['action2'])) $this->{$this->filter['action2']}() ;

     /*if (!$this->no_view_log)
     {?>
     <br><br>
     <h2>Результаты последних операций по импорту данных</h2><br>
     <?
        include_once(_DIR_EXT.'/log/report_log_events.php') ;
        $report_obj=new report_log_events() ;
        $report_obj->filter['actions']=array('import_skud_pass'=>1,'import_csv_pass'=>1,'import_persons_from_1c'=>1) ;
        //$report_obj->setting();
        $report_obj->view() ;
     } */
 }

   function check_persons()
   {   ?><h3>Запрос по ФЛ, имеющим более трех должностей (основной и совмещение)</h3><?
       $recs=execSQL('select personal_id,count(pkey) as cnt from obj_site_workers group by personal_id having cnt>2') ;
       print_2x_arr($recs);

       ?><h3>Запрос по ФЛ, имеющим более одной основой должности</h3><?
       $recs=execSQL('select personal_id,count(pkey) as cnt from obj_site_workers where is_main=1 group by personal_id having cnt>1') ;
       print_2x_arr($recs);

       ?><h3>Запрос по ФЛ, имеющим более одной должности по совмещению</h3><?
       $recs=execSQL('select personal_id,count(pkey) as cnt from obj_site_workers where is_second=1 group by personal_id having cnt>1') ;
       print_2x_arr($recs);

       ?><h3>Запрос по ФЛ, имеющим несколько одинаковых должностей</h3><?
       $recs=execSQL('select personal_id,parent,work_id,count(pkey) as cnt from obj_site_workers group by personal_id,parent,work_id having cnt>1') ;
       print_2x_arr($recs);
   }

  var $arr_data_source=array('xls'=>'XLS-файл',
           'xml'=>'XML-файл',
           'soap_emul'=>'Эмулятор SOAP 1C',
           ) ;
   var $arr_data_type=array('update'=>'Изменения',
           'full'=>'Полная выгрузка',
           ) ;

   function check_import_persons()
   {   ?><h2>Проверка импорта сотрудников</h2>
        <div id="panel_filter">
                   <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_CAB_DIR._CUR_REPORT?>">
                        <input type="hidden" name="filter[action]" value="check_import_persons">
                        <fieldset>
                            <div class="row">
                            <?   $this->filter_section_select('data_source','Источник данных',2,$this->arr_data_source) ;
                                 $this->filter_section_select('data_type','Тип данных',2,$this->arr_data_type,array('nospace_element'=>1)) ;
                            ?>
                                <section class="col col-2">
                                    <label class="label">Только чтения:</label>
                                    <label class="radio"><input type="checkbox" name="filter[read_only]" value="1" <?if (($this->filter['read_only'])) echo 'checked'?>><i></i>Да</label>
                                </section>
                            </div>
                        </fieldset>
                       <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Далее"></div>
                    </form>
        </div>
       <?
       switch($this->filter['data_source'])
       { case 'xls':  $this->check_import_persons_from_XLS($this->filter) ; break ;
         case 'xml':  $this->check_import_persons_from_XML() ; break ;
         case 'soap_emul':  $this->check_import_persons_from_SOAP_local_check() ;

       }
       unset($this->filter['action2']) ; // блокируем повторый вызов check_import_persons_from_SOAP_local_check через action2
   }


 function  check_import_propusk_from_skud()
 {
     magnit()->import_propusk_from_skud() ;
 }

 function  check_import_propusk_from_skud_RO()
 {
     magnit()->import_propusk_from_skud(array('mode'=>'RO')) ;
 }


 function  check_import_photo_from_skud()
 {
   magnit()->import_photo_from_skud() ;
 }

 function  check_import_photo_from_skud_RO()
 {
   magnit()->import_photo_from_skud(array('mode'=>'RO')) ;
 }

 function show_SOAP_tables()
 {   ?><h2>Последные данные, полученные из HR</h2><?
     $this->show_table_content('Организации','soap_HR_orgs',20) ;
     $this->show_table_content('Подразделения','soap_HR_otdels',20) ;
     $this->show_table_content('Должности','soap_HR_working',20) ;
     $this->show_table_content('Физические лица','soap_HR_members',20) ;
     $this->show_table_content('Персонал','soap_HR_personals',20) ;
     $this->show_table_content('Кадровая история','soap_HR_history',20) ;

 }

 function  show_table_content($title,$table_name,$count)
 { ?><h3><?echo $title?></h3><?
   $recs=execSQL('select * from '.$table_name.' order by upd desc limit '.$count,0,1) ;
   if (sizeof($recs)) foreach($recs as $i=>$rec) $recs[$i]['upd']=date('d.m.Y H:i:s',$rec['upd']) ;
   print_2x_arr($recs) ;
 }

 function show_HR_ESMO_tables()
 {   ?><h2>Таблицы HR из 1С, отобранные для ЭСМО, по 20 последних записей</h2><?
     $this->show_table_content('Организации','HR_orgs_ESMO',20) ;
     $this->show_table_content('Подразделения','HR_otdels_ESMO',20) ;
     $this->show_table_content('Должности','HR_working_ESMO',20) ;
 }


 function  check_import_persons_from_SOAP_local_view()
 {
   $list_files=get_files_list(_DIR_TO_ROOT.'/temp/',array('ext_pattern'=>'xml')) ;
   $recs=array() ;
   if (sizeof($list_files)) foreach($list_files as $fname)
   {   SOAP_import()->connect_SOURCE($fname) ;
       SOAP_import()->parse_source_headers() ;
       $rec=SOAP_import()->read_block_stats ;
       $rec['fname']=basename($fname);
       $rec['Операции']='<button class=v1 check_cmd="check_import_persons_from_SOAP_local_view" xml_file="'.basename($fname).'">Смотреть</button>&nbsp;&nbsp;&nbsp;
                         <button class=v1 check_cmd="check_import_persons_from_SOAP_local_put" xml_file="'.basename($fname).'">Принять</button>' ;
       $recs[SOAP_import()->SOAP_current_block_number]=$rec ;
   }
   print_2x_arr($recs) ;
   if ($_POST['xml_file']){?><br><h3><?echo $_POST['xml_file']?></h3><textarea style="width:100%;height:300px;"><?echo file_get_contents(_DIR_TO_ROOT.'/temp/'.$_POST['xml_file'])?></textarea><?}
 }

 function check_import_persons_from_SOAP_local_check()
 {   //damp_array($this->filter,1,-1) ;
     ?><div id="panel_filter">
                     <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                          <input type="hidden" name="filter[action]" value="check_import_persons">
                          <input type="hidden" name="filter[data_source]" value="<?echo $this->filter['data_source']?>">
                          <input type="hidden" name="filter[data_type]" value="<?echo $this->filter['data_type']?>">
                          <input type="hidden" name="filter[read_only]" value="<?echo $this->filter['read_only']?>">
                          <input type="hidden" name="filter[action2]" value="check_import_persons_from_SOAP_local_check">
                          <fieldset>
                              <div class="row" id="person_info">
                                   <section class="col col-2">
                                       <label class="label">ФИО сотрудника</label>
                                       <label class="input">
                                            <input type="text" name="filter[name]" placeholder="" SetAutoComplete cmd="autocomplette_personal_name" value="<?echo $this->filter['name']?>">
                                       </label>
                                   </section>
                                  <section class="col col-2">
                                      <label class="label">Номер пропуска</label>
                                      <label class="input">
                                          <input type="text" name="filter[propusk]" placeholder="" LANG="LAT" value="<?echo $this->filter['propusk']?>">
                                      </label>
                                  </section>
                                  <section class="col col-2">
                                      <label class="label">ID сотрудника</label>
                                      <label class="input">
                                          <input type="text" name="filter[personal_id]" placeholder="" LANG="LAT" value="<?echo $this->filter['personal_id']?>">
                                      </label>
                                  </section>
                                </div>
                          </fieldset>
                          <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Получить данные"></div>
                      </form>
               </div><br>
         <?

     $rec_personal_before=array() ;
     if ($this->filter['personal_id'])
     { $rec_personal_before=PERSONAL()->get_personal_by_id($this->filter['personal_id']) ;
       $rec_personal_before['fired_info_main']=execSQL_van('select uid,enabled,fired_data,fired_data_pause from obj_site_workers where personal_id='.$rec_personal_before['pkey'].' and is_main=1') ;
       $rec_personal_before['fired_info_second']=execSQL_van('select uid,enabled,fired_data,fired_data_pause from obj_site_workers where personal_id='.$rec_personal_before['pkey'].' and is_second=1') ;
     }

     if ($this->filter['xml_fname'])
     {   $fname=_TEMP_DIR.'/'.$this->filter['xml_fname'] ;
         //damp_array($this->filter) ;
         if (file_exists($fname))
          {  ?><h2>Обработка XML пакета</h2><a href="/temp/<?echo $this->filter['xml_fname']?>" target="_blank">Открыть <? echo $this->filter['xml_fname']?></a><br><?
             SOAP_import()->read_only=$this->filter['read_only'] ;
             SOAP_import()->full_update=($this->filter['data_type']=='full')?1:0 ;
             SOAP_import()->connect_SOURCE($fname) ;
             SOAP_import()->parse_source_headers() ;
             if (SOAP_import()->SOAP_XML_count_rows>0)
             { SOAP_import()->create_temp_tables() ;
               SOAP_import()->parse_SOURCE_to_DB() ;
               SOAP_import()->sync_TEMP_DB_ESMO() ;
               SOAP_import()->sync_workings_persons() ;
             }
          }
     }

     if ($this->filter['name'] or $this->filter['propusk'] or $this->filter['personal_id'])
     {  $rec_personal=array() ;
        if ($this->filter['name']) $rec_personal=PERSONAL()->get_personal_by_name($this->filter['name']) ;
        if ($this->filter['propusk']) $rec_personal=PERSONAL()->get_personal_by_propusk($this->filter['propusk']) ;
        if ($this->filter['personal_id']) $rec_personal=PERSONAL()->get_personal_by_id($this->filter['personal_id']) ;
        if ($rec_personal['pkey'])
        { if (!$rec_personal['uid'])
            {   PERSONAL()->personal_save($rec_personal['pkey'],array('uid'=>ENGINE()->generate_UID())) ;
                $rec_personal=PERSONAL()->get_personal_by_id($rec_personal['pkey']) ;
            }
          //damp_array($rec_personal,1,-1) ;
            $id=0 ;
          $arr_orgs_ids=PERSONAL()->get_arr_orgs_to_cur_account() ;
          //damp_array($this->filter) ;
          ?><h2>Текущие данные сотрудника</h2><?
          $this->panel_personal_table($rec_personal) ;
          $check_workers_main=execSQL_value('select pkey from obj_site_workers where personal_id='.$rec_personal['pkey'].' and is_main=1') ;
          if (!$check_workers_main) adding_rec_to_table('obj_site_workers',array('uid'=>ENGINE()->generate_UID(),
                                                                                 'personal_id'=>$rec_personal['pkey'],
                                                                                 'parent'=>$rec_personal['parent'],
                                                                                 'parent1'=>$rec_personal['parent1'],
                                                                                 'parent2'=>$rec_personal['parent2'],
                                                                                 'parent3'=>$rec_personal['parent3'],
                                                                                 'work_id'=>$rec_personal['working'],
                                                                                 'is_main'=>1,
                                                                                 'clss'=>212
                  ),array('debug'=>0)) ;

          /*$check_workers_second=execSQL_value('select pkey from obj_site_workers where personal_id='.$rec_personal['pkey'].' and is_second=1') ;
          /*if (!$check_workers_second) adding_rec_to_table('obj_site_workers',array('uid'=>ENGINE()->generate_UID(),
                                                                                 'personal_id'=>$rec_personal['pkey'],
                                                                                 'parent'=>$rec_personal['parent'],
                                                                                 'parent1'=>$rec_personal['parent1'],
                                                                                 'parent2'=>$rec_personal['parent2'],
                                                                                 'parent3'=>$rec_personal['parent3'],
                                                                                 'work_id'=>$rec_personal['working2'],
                                                                                 'is_second'=>1,
                                                                                 'clss'=>212
          ),array('debug'=>0)) ;
          */
          $recs_workers_before=execSQL('select pkey,uid,personal_id,parent,parent1,parent2,parent3,work_id,enabled,fired_data,fired_data_pause,is_main,is_second  from obj_site_workers where personal_id='.$rec_personal['pkey']) ;
          $recs_personal_before=execSQL('select pkey,uid,obj_name,dr,age,parent,parent1,parent2,parent3,working,working2,enabled,fired_data,fired_data_pause,person_status,workings_count,main_count,second_count from obj_site_personals where pkey='.$rec_personal['pkey']) ;
          $rec_workers_main=execSQL_van('select * from obj_site_workers where personal_id='.$rec_personal['pkey'].' and is_main=1') ;
          $rec_workers_secons=execSQL_van('select * from obj_site_workers where personal_id='.$rec_personal['pkey'].' and is_second=1') ;
          $otdel1_name=($rec_workers_main['parent3'])?  PERSONAL()->get_org_names_by_ids($rec_workers_main['parent3']):'' ;
          $otdel2_name=($rec_workers_secons['parent3'])?  PERSONAL()->get_org_names_by_ids($rec_workers_secons['parent3']):'' ;
          //$work_main_exists=execSQL_value('select is_main from soap_xml_block_wl where personal_id='.$rec_personal['pkey'].' and is_main=1') ;
          //$work_second_exists=execSQL_value('select is_second from soap_xml_block_wl where personal_id='.$rec_personal['pkey'].' and is_second=1') ;

          ?><h2>Новые данные сотрудника</h2><br>
            <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                <input type="hidden" name="filter[action]" value="check_import_persons">
                <input type="hidden" name="filter[data_source]" value="<?echo $this->filter['data_source']?>">
                <input type="hidden" name="filter[data_type]" value="<?echo $this->filter['data_type']?>">
                <input type="hidden" name="filter[read_only]" value="<?echo $this->filter['read_only']?>">
                <input type="hidden" name="filter[action2]" value="<?echo $this->filter['action2']?>">
                <input type="hidden" name="filter[_action]" value="<?echo $_POST['check_cmd']?>">
                <input type="hidden" name="filter[person_uid]" value="<?echo $rec_personal['uid']?>" />
                <input type="hidden" name="filter[person_id]" value="<?echo $rec_personal['pkey']?>" />
                <fieldset>
                    <div class="row" id="person_info">
                         <section class="col col-2">
                             <label class="label">ФИО сотрудника</label>
                             <label class="input">
                                  <input type="text" name="filter[name]" placeholder="" value="<?echo $rec_personal['obj_name']?>">
                             </label>
                         </section>
                        <section class="col col-2">
                            <label class="label">Дата рождения</label>
                            <label class="input">
                                <input type="text" name="filter[dr]" placeholder="" value="<?echo $rec_personal['dr']?>">
                            </label>
                        </section>
                        <section class="col col-2">
                            <label class="label">Пол</label>
                            <label class="radio"><input type="radio" name="filter[pol]" value="0" <?if (!$rec_personal['pol']) echo 'checked'?>><i></i> Мужской</label>
                            <label class="radio"><input type="radio" name="filter[pol]" value="1" <?if ($rec_personal['pol']) echo 'checked'?>><i></i> Женский</label>
                        </section>
                      </div>
                </fieldset>
                <!-- ОСНОВНОЕ МЕСТО РАБОТЫ -->
                <fieldset>
                    <div class="row" id="person_info">
                         <? REPORT()->filter_section_input_text('uid1','GUID сотрудника:',2,array('cur_value'=>$rec_workers_main['uid'])) ;
                            REPORT()->filter_section_select('org_id1','Основное место работы - организация:',2,$arr_orgs_ids,array('cur_value'=>$rec_workers_main['parent2'])) ;
                            REPORT()->filter_section_input_text('otdel_id1','Подразделение:',2,array('_auto_complete'=>"autocomplette_personal_name",'cur_value'=>$otdel1_name)) ;
                            REPORT()->filter_section_select('working1','Должность:',2,_IL('IL_works')->recs,array('cur_value'=>$rec_workers_main['work_id'])) ;
                            REPORT()->filter_section_input_text('date1','Дата операции:',1,array('type'=>'date','cur_value'=>date('Y-m-d'))) ;
                            $ss=0 ;
                         ?>
                        <section class="col col-3">
                            <label class="label">Статус:</label>
                            <label class="radio">
                              <label class="radio"><input type="radio" name="filter[status1]" value="1" <?if ($rec_workers_main['enabled'] and !$rec_workers_main['fired_data_pause']) { echo 'checked' ; $ss=1 ; }?>><i></i>Активно</label>
                              <label class="radio"><input type="radio" name="filter[status1]" value="2" <?if (($rec_workers_main['uid'] and !$rec_workers_main['enabled']) or $rec_workers_main['fired_data_pause']) { echo 'checked' ; $ss=2 ; }?>><i></i>Уволен</label>
                              <label class="radio"><input type="radio" name="filter[status1]" value="3" <?if (!$ss) echo 'checked'?>><i></i>Нет данных</label>
                        </section>
                      </div>
                </fieldset>
                <!-- СОВМЕЩЕНИЕ -->
                <fieldset>
                    <div class="row" id="person_info">
                         <? REPORT()->filter_section_input_text('uid2','GUID сотрудника:',2,array('cur_value'=>$rec_workers_secons['uid'])) ;
                            REPORT()->filter_section_select('org_id2','Совмещение- организация:',2,$arr_orgs_ids,array('cur_value'=>$rec_workers_secons['parent2'])) ;
                            REPORT()->filter_section_input_text('otdel_id2','Подразделение:',2,array('_auto_complete'=>"autocomplette_personal_name",'cur_value'=>$otdel2_name)) ;
                            REPORT()->filter_section_select('working2','Должность:',2,_IL('IL_works')->recs,array('cur_value'=>$rec_workers_secons['work_id'])) ;
                            REPORT()->filter_section_input_text('date2','Дата операции:',1,array('type'=>'date','cur_value'=>date('Y-m-d'))) ;
                            $ss=0 ;
                         ?>
                        <section class="col col-3">
                            <label class="label">Статус:</label>
                            <label class="radio">
                                <label class="radio"><input type="radio" name="filter[status2]" value="1" <?if ($rec_workers_secons['enabled'] and !$rec_workers_secons['fired_data_pause']) { echo 'checked' ; $ss=1 ; }?>><i></i>Активно</label>
                                <label class="radio"><input type="radio" name="filter[status2]" value="2" <?if (($rec_workers_secons['uid'] and !$rec_workers_secons['enabled']) or $rec_workers_secons['fired_data_pause']) { echo 'checked' ; $ss=2 ;}?>><i></i>Уволен</label>
                                <label class="radio"><input type="radio" name="filter[status2]" value="3" <?if (!$ss) echo 'checked'?>><i></i>Нет данных</label>
                        </section>
                      </div>
                </fieldset>
                <div id="panel_buttons">
                    <button type="submit" class="button v2" cmd="magnit/check_XML_import">Отправить XML в ЭСМО</button>&nbsp;&nbsp;&nbsp;
                </div>
            <div style="padding:20px 20px;">
                <label><input type="hidden" name="setting[SES_show_esmo_table]" value="0"><input type="checkbox" class=v2 cmd="aspmo_setting/save_setting" name="setting[SES_show_esmo_table]" value="1" <?if ($_SESSION['SES_show_esmo_table']) echo 'checked'?>> Показать дамп таблиц ЭСМО</label>&nbsp;&nbsp;
                <label><input type="hidden" name="setting[SES_show_source_table]" value="0"><input type="checkbox" class=v2 cmd="aspmo_setting/save_setting" name="setting[SES_show_source_table]" value="1"  <?if ($_SESSION['SES_show_source_table']) echo 'checked'?>> Показать дамп таблиц источников</label>&nbsp;&nbsp;
                <button class="button_small v2" cmd="magnit/close_fired_pause" personal_id="<?echo $rec_personal['pkey']?>">Завершить отложенное увольнение</button>
                <button class="button_small v2" cmd="magnit/remove_work_main" personal_id="<?echo $rec_personal['pkey']?>">Удалить данные по основной должности</button>
                <button class="button_small v2" cmd="magnit/remove_work_second" personal_id="<?echo $rec_personal['pkey']?>">Удалить данные по совмещаемой должности</button>
            </div>
            </form><br>
            <div id="panel_new_data"><??></div>
            <div id="panel_log">
                <?  $fname=_TEMP_DIR.'/'.$this->filter['xml_fname'] ;
                    if (file_exists($fname))
                     {  ?><br><h2>Было-Стало</h2><?
                        $rec_personal_after=PERSONAL()->get_personal_by_id($this->filter['personal_id']) ;
                        if ($rec_personal_after['pkey'])
                        { $rec_personal_after['fired_info_main']=execSQL_van('select uid,enabled,fired_data,fired_data_pause from obj_site_workers where personal_id='.$rec_personal_after['pkey'].' and is_main=1') ;
                          $rec_personal_after['fired_info_second']=execSQL_van('select uid,enabled,fired_data,fired_data_pause from obj_site_workers where personal_id='.$rec_personal_after['pkey'].' and is_second=1') ;
                        }

                        $this->panel_personal_table($rec_personal_before,$rec_personal_after) ;

                        if ($_SESSION['SES_show_esmo_table'])
                        {    $recs_personal_after=execSQL('select pkey,uid,obj_name,dr,age,parent,parent1,parent2,parent3,working,working2,enabled,fired_data,fired_data_pause,person_status,workings_count,main_count,second_count from obj_site_personals where pkey='.$rec_personal['pkey']) ;
                             ?><br><h2>Таблица физических лиц</h2><?
                             ?><h3>Было</h3><?
                             print_2x_arr($recs_personal_before) ;
                             ?><h3>Стало</h3><?
                             print_2x_arr($recs_personal_after) ;


                             $recs_workers_after=execSQL('select pkey,uid,personal_id,parent,parent1,parent2,parent3,work_id,enabled,fired_data,fired_data_pause,is_main,is_second from obj_site_workers where personal_id='.$rec_personal['pkey']) ;
                             ?><br><h2>Таблица сотрудников организаций</h2><?
                             ?><h3>Было</h3><?
                             print_2x_arr($recs_workers_before) ;
                             ?><h3>Стало</h3><?
                             print_2x_arr($recs_workers_after) ;
                        }

                        if ($_SESSION['SES_show_source_table'])
                        {    $recs_fl=execSQL('select FizicheskoeLitso,TabelnyyNomer,DataRozhdeniya,Pol,Familiya,Imya,Otchestvo,personal_id,obj_name,dr,poll from '.SOAP_import()->table_fz) ;
                             ?><br><h2>Таблица temp_table_fz</h2><?
                             print_2x_arr($recs_fl) ;

                             //$recs_wl=execSQL('select Ref,Sotrudnik,Podrazdelenie,PodrazdelenieNomer,PodrazdelenieNaimenovanie,Organizatsiya,DolzhnostNaimenovanie,DataPriema,DataUvolneniya,VidZanyatosti,Sostoyanie,worker_id,personal_id,org_id,otdel_id,work_id,status,is_main,is_second,fired_data from soap_xml_block_wl') ;
                             $recs_wl=execSQL('select Sotrudnik,Organizatsiya,PodrazdelenieNaimenovanie,DolzhnostNaimenovanie,DataUvolneniya,VidZanyatosti,worker_id,personal_id,org_id,otdel_id,work_id,is_main,is_second,fired_data from '.SOAP_import()->table_so) ;
                             ?><br><h2>Таблица temp_table_so</h2><?
                             print_2x_arr($recs_wl) ;
                             ?><br><br><?
                             $this->panel_log_events($rec_personal['pkey']) ;
                        }
                     }
                     else echo 'Файл '.$fname.' не найден<br>' ;

                ?>
            </div>

            <?
            //damp_array($_POST,1,-1) ;
            //damp_array($rec_personal,1,-1) ;
        }
        else echo '<div class="alert">Сотрудник  не найден</div>' ;

     }
     $this->no_view_log=1 ;
 }

 function panel_log_events($personal_id)
  { include_once(_DIR_EXT.'/log/report_log_events.php') ;
    $report_obj=new report_log_events() ;
   // $report_obj->filter['reffer']=$this->rec_personal['_reffer'];
    $report_obj->filter=array() ;
    $report_obj->filter['personal_id']=$personal_id;
    $report_obj->filter['order']='pkey desc';
   // $report_obj->setting() ;
    $report_obj->view_as_HTML(array('limit'=>'limit 0,10')) ;
  }

 function panel_personal_table($rec_personal,$rec_personal_new=array())
 {   //damp_array($rec_personal_new,1,-1) ;
     ?><table class="basic fz_small full auto">
       <tr>
           <th>UID</th>
           <th>ФИО</th>
           <th>Дата рожд.</th>
           <th>Организация</th>
           <th>Подразделение</th>
           <th>Должность</th>
           <th>Должность совм.</th>
           <th>Отложенное увольнение</th>
           <th>Статус</th>
           <th>Комментарий</th>
       </tr>
       <tr><td><?echo $rec_personal['uid']?></td>
           <td><a href="/window/personal/person/<?echo $rec_personal['pkey']?>/" class="new_window"><?echo $rec_personal['obj_name']?></a></td>
           <td><?echo $rec_personal['dr']?></td>
           <td><?if ($rec_personal['parent2']) echo PERSONAL()->get_org_names_by_ids($rec_personal['parent2'])?></td>
           <td><?if ($rec_personal['parent3']) echo PERSONAL()->get_org_names_by_ids($rec_personal['parent3'])?></td>
           <td><?echo _IL('IL_works')->recs[$rec_personal['working']]['obj_name']?></td>
           <td><?echo _IL('IL_works')->recs[$rec_personal['working2']]['obj_name']?></td>
           <td><?echo ($rec_personal['fired_data_pause'])? '<span class="red">ОТЛОЖЕННОЕ УВОЛЬНЕНИЕ</span><br>'.date('d.m.Y H:i',$rec_personal['fired_data_pause']):'<span class="green">-</span>'?></td>
           <td><?echo ($rec_personal['enabled'])? '<span class="green">АКТИВЕН</span>':'<span class="red">УВОЛЕН</span><br>'.date('d.m.Y H:i',$rec_personal['fired_data'])?></td>
           <td><? if (sizeof($rec_personal['fired_info_main']))
                   {  $fired_info=$rec_personal['fired_info_main'] ;
                      if ($fired_info['enabled'] and $fired_info['fired_data_pause']) echo 'Отложенное увольнение по основной должности, до '.date('d.m.Y H:i',$fired_info['fired_data_pause']).'<br>' ;
                      if ($fired_info['uid'] and !$fired_info['enabled']) echo 'Уволен по основной должности '.date('d.m.Y H:i',$fired_info['fired_data']).'<br>' ;
                      $fired_info=$rec_personal['fired_info_second'] ;
                      if ($fired_info['enabled'] and $fired_info['fired_data_pause']) echo 'Отложенное увольнение по совмещаемой должности, до '.date('d.m.Y H:i',$fired_info['fired_data_pause']).'<br>' ;
                      if ($fired_info['uid'] and !$fired_info['enabled']) echo 'Уволен по совмещаемой должности '.date('d.m.Y H:i',$fired_info['fired_data']).'<br>' ;
                   }
               ?>
           </td>
       </tr>
      <?if (sizeof($rec_personal_new))
      {?><tr><td><?echo $rec_personal_new['uid']?></td>
             <td><?echo $rec_personal_new['obj_name']?></td>
             <td><?echo $rec_personal_new['dr']?></td>
             <td><?if ($rec_personal_new['parent2']) echo PERSONAL()->get_org_names_by_ids($rec_personal_new['parent2'])?></td>
             <td><?if ($rec_personal_new['parent3']) echo PERSONAL()->get_org_names_by_ids($rec_personal_new['parent3'])?></td>
             <td><?echo _IL('IL_works')->recs[$rec_personal_new['working']]['obj_name']?></td>
             <td><?echo _IL('IL_works')->recs[$rec_personal_new['working2']]['obj_name']?></td>
             <td><?echo ($rec_personal_new['fired_data_pause'])? '<span class="red">ОТЛОЖЕННОЕ УВОЛЬНЕНИЕ</span><br>'.date('d.m.Y H:i',$rec_personal_new['fired_data_pause']):'<span class="green">-</span>'?></td>
             <td><?echo ($rec_personal_new['enabled'])? '<span class="green">АКТИВЕН</span>':'<span class="red">УВОЛЕН</span><br>'.date('d.m.Y H:i',$rec_personal_new['fired_data'])?></td>
             <td><? if (sizeof($rec_personal_new['fired_info_main']))
                  {  $fired_info=$rec_personal_new['fired_info_main'] ;
                     if ($fired_info['enabled'] and $fired_info['fired_data_pause']) echo 'Отложенное увольнение по основной должности, до '.date('d.m.Y H:i',$fired_info['fired_data_pause']).'<br>' ;
                     if ($fired_info['uid'] and !$fired_info['enabled']) echo 'Уволен по основной должности '.date('d.m.Y H:i',$fired_info['fired_data']).'<br>' ;
                     $fired_info=$rec_personal_new['fired_info_second'] ;
                     if ($fired_info['enabled'] and $fired_info['fired_data_pause']) echo 'Отложенное увольнение по совмещаемой должности, до '.date('d.m.Y H:i',$fired_info['fired_data_pause']).'<br>' ;
                     if ($fired_info['uid'] and !$fired_info['enabled']) echo 'Уволен по совмещаемой должности '.date('d.m.Y H:i',$fired_info['fired_data']).'<br>' ;
                  }
              ?>
          </td>

         </tr>
      <?}?>
     </table><br><?
 }

 function  check_import_persons_from_SOAP_local_put()
 {  $list_files=get_files_list(_DIR_TO_ROOT.'/temp/',array('ext_pattern'=>'xml')) ;

    $recs=array() ;
    if (sizeof($list_files)) foreach($list_files as $fname)
    {   SOAP_import()->connect_SOURCE($fname) ;
        SOAP_import()->parse_source_headers() ;
        $rec=SOAP_import()->read_block_stats ;
        $rec['fname']=basename($fname);
        $rec['Операции']='<button class=v1 check_cmd="check_import_persons_from_SOAP_local_view" xml_file="'.basename($fname).'">Смотреть</button>&nbsp;&nbsp;&nbsp;
                          <button class=v1 check_cmd="check_import_persons_from_SOAP_local_put" xml_file="'.basename($fname).'">Принять</button>' ;
        $recs[SOAP_import()->SOAP_current_block_number]=$rec ;
    }
   if (sizeof($recs)) print_2x_arr($recs) ;

   if ($_POST['xml_file'])
   { ?><br><h3><?echo $_POST['xml_file']?></h3><textarea style="width:100%;height:300px;"><?echo file_get_contents(_DIR_TO_ROOT.'/temp/'.$_POST['xml_file'])?></textarea><?
     $this->check_import_persons_from_SOAP_update(array('local_fname'=>_DIR_TO_ROOT.'/temp/'.$_POST['xml_file'])) ;
   }
 }

 function check_import_persons_from_SOAP_full_RO()
 {   include_once(_DIR_TO_MODULES.'/engine/i_backgroup_process.php') ;
     $back_process=new i_backgroup_process('/services/magnit/import_personal_full_RO/') ;
     $back_process->panel_background_process() ;
 }

 function check_import_persons_from_SOAP_change_RO()
 {   include_once(_DIR_TO_MODULES.'/engine/i_backgroup_process.php') ;
     $back_process=new i_backgroup_process('/services/magnit/import_personal_change_RO/') ;
     $back_process->panel_background_process() ;
 }

 function check_import_persons_from_SOAP_full()
 {   include_once(_DIR_TO_MODULES.'/engine/i_backgroup_process.php') ;
     $back_process=new i_backgroup_process('/services/magnit/import_personal_full/') ;
     $back_process->panel_background_process() ;
 }

 function check_import_persons_from_SOAP_change()
 {   include_once(_DIR_TO_MODULES.'/engine/i_backgroup_process.php') ;
     $back_process=new i_backgroup_process('/services/magnit/import_personal_change/') ;
     $back_process->panel_background_process() ;
 }

 function  check_import_persons_from_SOAP_update($options=array())
 {   //ob_start() ; $t1=fixed_time() ;
     //damp_array($this->filter) ;
     ob_start() ;

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

     SOAP_import()->read_only=$this->filter['read_only'] ;

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

     SOAP_import()->parse_source_headers() ;

     SOAP_import()->create_temp_tables() ;

     SOAP_import()->parse_SOURCE_to_DB() ;

     SOAP_import()->sync_TEMP_DB_ESMO() ;

     SOAP_import()->sync_workings_persons() ;

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

 function show_mail_recs_in_db()
 {
     $recs=execSQL('select pkey as mail_id,c_data,sender,obj_name,size,status from obj_site_inmail order by pkey desc limit 100') ;
     print_2x_arr($recs) ;
 }

 function show_mail_recs_in_db_attach()
 {   $arr_status=array(0=>'Новое',1=>'Обработано',9=>'Ошибка') ;
     $recs=execSQL('select pkey as attach_id,parent as mail_id,obj_name,type,bytes,saved_fname,status from obj_site_inmail_attach order by pkey desc limit 100') ;
     if (sizeof($recs)) foreach($recs as $i=>$rec) if (isset($arr_status[$rec['status']])) $recs[$i]['status']=$arr_status[$rec['status']]   ;
     print_2x_arr($recs) ;
 }

 function check_import_persons_from_XLS($options=array())
 {
     ?><h2>Проверка загрузки сотрудников из файла XLS</h2><?
     //$this->read_only=($_POST['read_only'])? 1:0 ;
     //if ($_POST['cmd']=='upload_file') $this->panel_upload_file() ;
     ?><div id="panel_upload_promt"><form action="" method="POST" enctype="multipart/form-data">
        <p>Загрузите список сотрудников, используя заранее подготовленный файл Excel. <a href="<?echo _PATH_TO_EXT?>/aspmo_personal/demo/members.xls">Образец файла</a><p>
        <p><strong>Внимание!</strong><p>
        <ul class="info"><li>Записи из файла будут добавлены к существующим записям базы</li>
            <li>При совпадении ФИО сотрудника записи в базе будут затерты.</li>
        </ul>
        <div class=comment>Размер файла не более 1М, формат файла - Excel XLS.</div>

        <div class=buttons>
            <input name="upload_file[]" type="file" size="50">
            <input type="submit" value="Загрузить файл" class=button_green>&nbsp;&nbsp;&nbsp;&nbsp;
            <?if ($options['read_only']) {?><input type="hidden" name=read_only value="1"><?}?>
            <?if ($options['data_type']=='full') {?><input type="hidden" name=full_update value="1"><?}?>
        </div>
       </form>
       </div><?

     if (isset($_FILES['upload_file'])) $this->upload_XLS_file() ;
   }

   var $xls_fname ;
   var $session_UID ;
   var $fname ;
   var $log_fname ;

   function upload_XLS_file()
    { set_time_limit(0) ;
      $result=0 ;
      $this->session_UID=ENGINE()->generate_UID() ;
      // загружаем файл
      if (sizeof($_FILES))
        { $recs_files=conver_FILES_to_recs($_FILES['upload_file']) ;
          if (sizeof($recs_files[0]))
            { //if ($recs_files[0]['type']=='application/vnd.ms-excel')
              { ?><h2>Загружаем данные из файла "<?echo $recs_files[0]['name']?>"</h2><?
                $this->fname=$recs_files[0]['name'] ;
                $this->xls_fname='/temp/members_'.$this->session_UID.'.xls' ;
                $result=move_uploaded_file($recs_files[0]['tmp_name'],_DIR_TO_ROOT.$this->xls_fname) ;
                if ($result) echo 'Файл загружен в: <a target=_blank href="'.$this->xls_fname.'">'.$this->xls_fname.'</a><br>' ;
                else
                { echo '<div class=alert>Не удалось загрузить файл: <a target=_blank href="'.$this->xls_fname.'">'.$this->xls_fname.'</a></div>' ;
                  ?><h3>upload info</h3><?
                  damp_array($recs_files[0],1,-1) ;
                  $perm=ENGINE()->get_file_perms_info(_DIR_TO_ROOT.'/temp/',array('symbol'=>1)) ;
                  ?><h3>/temp/ permissions</h3><?
                  damp_array($perm,1,-1) ;

                }
              }
            }
        }

      if (!$result) return ;
      $this->log_fname=FILE_LOG($this->session_UID)->log_fname ;
      $page_output=_DIR_TO_ROOT.'/temp/result_page_'.$this->session_UID.'.html' ;


      // делаем JS вывод лога
      ?><script type="text/javascript">
            $j(document).ready(function()
                        {  $j('body').everyTime(1000,'update_upload_log',function()
                        {  var url='<?echo $this->log_fname?>' ;    // url для получения статики через скрипт
                           console.log(url) ;
                           jQuery.get( url,{},exec_get_html,'json');
                        }) ;
            })
            var last_mess_id=0 ;
            function exec_get_html(data, textStatus, jqXHR)
                  { if (textStatus=='success' && data!=null) $j.each(data,function(mess_id,value)
                    {  if (mess_id!=last_mess_id)
                          { console.log(mess_id+' => '+value.text) ;
                            $j('#panel_log_uplod').append('<div class=item>'+value.text+'</div>');
                            $j('#panel_log_uplod')[0].scrollTop = 9999;
                            last_mess_id=mess_id ;
                            if (value.text=='END')
                            {   $j('body').stopTime('update_upload_log') ;
                                var url='/temp/full_<?echo basename($this->log_fname)?>' ;    // url для получения статики через скрипт
                                jQuery.get( url,{},exec_get_html_full,'text');
                                var url2='/temp/<?echo basename($page_output)?>' ;    // url для получения статики через скрипт
                                jQuery.get( url2,{},exec_get_html_report,'text');
                            }
                          }
                    }) ;
                 }
            function exec_get_html_full(data, textStatus, jqXHR)
                  { if (textStatus=='success' && data!=null)
                    {  $j('#panel_log_uplod').html(data);
                       $j('#panel_log_uplod')[0].scrollTop = 9999;
                    }
                 }
            function exec_get_html_report(data, textStatus, jqXHR)
                  { if (textStatus=='success' && data!=null)
                    {  $j('#panel_result_form').html(data);
                       //$j('#panel_result_form')[0].scrollTop = 9999;
                    }
                 }
        </script>
        <?

      include(_DIR_EXT.'/aspmo_personal/i_upload_persons.php') ;
      $obj_upload_persons=new i_upload_persons(array('uid'=>$this->session_UID)) ;
      $obj_upload_persons->exec() ;

      echo '<br><br>Лог этапов: <a href="/temp/full_'.basename($this->log_fname).'" target=_blank>'.basename($this->log_fname).'</a><br>' ;

      ?><h3>Лог загрузки:</h3>
      <div id=panel_log_uplod style="width:100%;height:400px;overflow:scroll;border:1px solid darkgreen;"></div><?
    }


 function check_import_persons_from_XML($options=array())
 {
     ?><h2>Проверка загрузки сотрудников из файла XML</h2><?
     //$this->read_only=($_POST['read_only'])? 1:0 ;
     //if ($_POST['cmd']=='upload_file') $this->panel_upload_file() ;
     ?><div id="panel_upload_promt"><form action="" method="POST" enctype="multipart/form-data"><input type="hidden" name="action" value="upload_XML_file">
        <p>Загрузите список сотрудников, используя заранее подготовленный файл XML<p>
        <div class=buttons>
            <input name="upload_file[]" type="file" size="50">
            <input type="submit" value="Загрузить файл" class=button_green>&nbsp;&nbsp;&nbsp;&nbsp;
             <?if ($options['read_only']) {?><input type="hidden" name=read_only value="1"><?}?>
             <?if ($options['data_type']=='full') {?><input type="hidden" name=full_update value="1"><?}?>
        </div>
       </form>
       </div><?
     if (isset($_FILES['upload_file'])) $this->upload_XLS_file() ;
   }

   function upload_XML_file()
    { ob_start() ;
      set_time_limit(0) ;
      $result=0 ;
      $this->session_UID=ENGINE()->generate_UID() ;
      // загружаем файл
      if (sizeof($_FILES))
        { $recs_files=conver_FILES_to_recs($_FILES['upload_file']) ;
          if (sizeof($recs_files[0]))
            { //if ($recs_files[0]['type']=='application/vnd.ms-excel')
              { ?><h2>Загружаем данные из файла "<?echo $recs_files[0]['name']?>"</h2><?
                $this->fname=$recs_files[0]['name'] ;
                $fname='/temp/members_'.$this->session_UID.'.xml' ;
                $result=move_uploaded_file($recs_files[0]['tmp_name'],_DIR_TO_ROOT.$fname) ;
                if ($result)
                { echo 'Файл загружен в: <a target=_blank href="'.$fname.'">'.$fname.'</a><br>' ;
                  SOAP_import()->connect_SOURCE(_DIR_TO_ROOT.$fname) ;
                  SOAP_import()->read_only=$_POST['read_only'] ;
                  SOAP_import()->full_update=$_POST['full_update'] ;

                  SOAP_import()->parse_source_headers() ;
                  SOAP_import()->create_temp_tables() ;
                  SOAP_import()->parse_SOURCE_to_DB() ;

                  if (!$_POST['read_only'])
                    {   SOAP_import()->sync_TEMP_DB_ESMO() ;
                  SOAP_import()->sync_workings_persons() ;
                }
                else
                    {   ?><h2>Таблица-источник физических лиц</h2><?
                        $recs=execSQL('select * from '.SOAP_import()->table_fz);
                        print_2x_arr($recs) ;
                        ?><h2>Таблица-источник сотрудников организаций</h2><?
                        $recs=execSQL('select * from '.SOAP_import()->table_so);
                        print_2x_arr($recs) ;
                    }
                }
                else
                { echo '<div class=alert>Не удалось загрузить файл: <a target=_blank href="'.$fname.'">'.$fname.'</a></div>' ;
                  ?><h3>upload info</h3><?
                  damp_array($recs_files[0],1,-1) ;
                  $perm=ENGINE()->get_file_perms_info(_DIR_TO_ROOT.'/temp/',array('symbol'=>1)) ;
                  ?><h3>/temp/ permissions</h3><?
                  damp_array($perm,1,-1) ;
                }
              }
            }
        }
        $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 файла<br></nr><a href="/logs/'.str_replace(array('[fname=',']'),'',basename($log_fname)).'" target=_blank>Отчет</a><br>')  ;

    }


 function check_mails()
 {   include_once(_DIR_TO_MODULES."/engine/i_mailbox.php");
     $mail_box=new c_mailbox()  ;
     $mail_box->read_mail() ;

 }


 function view_SKUD_pass()
 {
     ?><h2>Буферная таблица пропусков СКУД</h2><?
     $cnt=execSQL_value('select count(*) from SKUD_pass') ;
     echo 'В буферной базе СКУД <strong>'.$cnt.'</strong> записей, в выборке ограничение на 100 записей<br><br>' ;
     $recs=execSQL('select * from SKUD_pass limit 100',0,1) ;
     print_2x_arr($recs) ;
     $this->no_view_log=1 ;

 }

 function view_SKUD_photo()
 {
     ?><h2>Буферная таблица фото СКУД</h2><?
     $cnt=execSQL_value('select count(*) from SKUD_photo') ;
     echo 'В буферной базе СКУД <strong>'.$cnt.'</strong> записей, в выборке ограничение на 10 записей<br><br>' ;
     $recs=execSQL('select * from SKUD_photo limit 10',0,1) ;
     print_2x_arr($recs) ;
     $this->no_view_log=1 ;

 }

 function view_propusk_from_skud()
 {
    ?><h2>Поиск пропуска в буферной таблице СКУД</h2><?
     $cnt=execSQL_value('select count(*) from SKUD_pass') ;
     echo 'В буферной базе СКУД <strong>'.$cnt.'</strong> записей<br><br>' ;
     ?><form>Пропуск или UID: <input type="text" name="s" value="<?echo htmlspecialchars($_POST['s'])?>"> <input type="submit" class="v1" check_cmd="view_propusk_from_skud" value="Искать"></form><br><br><?
     if ($_POST['s'])
     {   $text=addslashes($_POST['s']) ;
         $recs=execSQL('select t1.*,t2.pkey as personal_id_by_UID,t2.obj_name as personal_name_by_UID,t3.pkey as personal_id_by_propusk,t3.obj_name as personal_name_by_propusk 
                        from SKUD_pass t1 
                        left join obj_site_personals t2 on t2.uid=t1.UID 
                        left join obj_site_personals t3 on t3.propusk=t1.propusk 
                        where t1.UID like "'.$text.'%" or t1.propusk like "'.$text.'%"',0,1) ;
         if (sizeof($recs))
         { ?><table class="basic fz_small"><tr><th>#</th><th>UID</th><th>Пропуск</th><th>Сотрудник по UID</th><th>Сотрудник по пропуску</th></tr><?
           foreach($recs as $i=>$rec)
           { ?><tr>
               <td><?echo $i+1?></td>
               <td><?echo $rec['uid']?></td>
               <td><?echo $rec['propusk']?></td>
               <td <?if ($rec['personal_id_by_UID']==$rec['personal_id_by_propusk']) echo 'colspan=2'?>><?if ($rec['personal_id_by_UID']) echo '<a href="/window/personal/person/'.$rec['personal_id_by_UID'].'/" class="new_window">'.$rec['personal_name_by_UID'].'</a>'?></td>
               <?if ($rec['personal_id_by_UID']!=$rec['personal_id_by_propusk']){?><td><?if ($rec['personal_id_by_propusk']) echo '<a href="/window/personal/person/'.$rec['personal_id_by_propusk'].'/" class="new_window">'.$rec['personal_name_by_propusk'].'</a>'?></td><?} ?>
             <?
           }
           ?></table><?

         } else {?><div class="alert">Информация отсутствует</div><?}
         //execSQL('select * from SKUD_pass',2) ;

     }
     $this->no_view_log=1 ;

 }






}



?>
