<?php
/**
 * CodeIgniter report view
 *
 * @category CodeIgniter
 * @license /_licenses/untermStrich/agb_normal.pdf
 * @author Christian Koller
 * @copyright 2009 untermStrich
 * @package views
 * @version $Id: View_xml.php 23466 2022-02-02 13:24:33Z christian $
*/

if (!defined('BASEPATH')) { exit('No direct script access allowed'); }

require_once APPPATH.'us_libraries/US_report_view_result.php';

/**
 * Create usexchng file
 */
class View_usexchng extends US_report_view_result
{

    /**
     * Process the report based on the view mode
     *
     * @param   integer $mode   One of the US_report_view_result::M_... modes
     * @return  mixed   Either void or the filename
     *
     * @see US_report_view_result::M_DIRECT
     * @see US_report_view_result::M_FILE
     */
    protected function process($mode)
    {
        ini_set('memory_limit', '1000M');
        set_time_limit(720);
        
        $file_name_usexchng = Report_config::get_report_tmp_name('uex');
        $iv = openssl_random_pseudo_bytes(16);
        $key1 = random_int(10000000, 99999999);
        $key = hash('sha256', '494w74gfdd'.$key1.'df0cwrv4gr', true);
        
        file_put_contents($file_name_usexchng, $iv.$key1);
        file_put_contents($file_name_usexchng, openssl_encrypt(file_get_contents($this->file_name), 'AES-256-CBC', $key, 0, $iv), FILE_APPEND);
        
        if ($mode===US_report_view_result::M_FILE) {
            return $file_name_usexchng;
        } else {
            Report::set_header($this->viewinfo);
            readfile($file_name_usexchng);
        }

    }

} // END class View_xml
