<?
include_once(_DIR_EXT.'/HTML/c_page_XML_AJAX.php') ;
//include_once('messages.php') ;
class c_page_ajax extends c_page_XML_AJAX
{

    function report_select()
       { $rec_report=REPORTS()->reports_list[$_POST['report_type']] ;
         $script_dir=$rec_report['script_dir'] ;
         $class_name=$rec_report['class_name'] ;
         if (file_exists(_DIR_EXT.'/'.$script_dir))
            { include_once(_DIR_EXT.'/'.$script_dir) ;
              if (class_exists($class_name))
              { $this->go_url='/cab/reports/'.$_POST['report_type'].'/' ;
           }
           }
         }

       function view_as_html()
       {  $url=REPORT()->prepare_url($_POST['filter'],array('base_url'=>$_POST['filter_dir'])) ;
          $this->go_url=$url ;
       }

       function view_as_pdf()
       {  $_POST['filter']['view']=($_POST['mode']=='HTML2PDF')? 'prePDF':'PDF' ;
          $url=REPORT()->prepare_url($_POST['filter'],array('base_url'=>$_POST['filter_dir'])) ;
          $this->go_url=$url ;
       }
    
    
       function to_print()
       {  $_POST['filter']['view']='print' ;
          $url=REPORT()->prepare_url($_POST['filter'],array('base_url'=>$_POST['filter_dir'])) ;
          $this->go_url=$url ;
       }

  
  function update_log_view()
  {   ob_start() ;
     $outputfile='log_'.$_POST['cmd_uid'].'.txt' ;
     if (file_exists(_TEMP_DIR.$outputfile)) echo file_get_contents(_TEMP_DIR.$outputfile) ;
     else   echo 'Не найден лог подготовки документа <strong>'.$outputfile.'</strong><br>' ;
     $text=ob_get_clean() ;
     $this->add_element('log_view.HTML',nl2br($text)) ;
     if (strpos($text,'Done')!==false  and strpos($text,'100%')!==false)
      { $this->add_element('buttons777.HTML','<button class="v1 button_green" href="'.$_POST['url_page_doc_view'].'">Далее</button>') ;
        $this->add_element('go_url',$_POST['url_page_doc_view']) ;   //  автоматичнский переход на страницу документа
        $this->add_element('JSCODE','<script type="text/javascript">$j("#log_view").stopTime("update_log_view");</script>') ;
      }

  }

}