<?php
/**
 * CodeIgniter report view
 *
 * @category CodeIgniter
 * @license /_licenses/untermStrich/agb_normal.pdf
 * @author Christian Koller
 * @copyright 2009 untermStrich
 * @package views
 * @version $Id$
*/

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

require_once APPPATH.'us_libraries/US_report_view_result.php';

/**
 * A view for Smarty based reports
 */
class View_smarty 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)
    {
        $this->CI->load->library('US_Smartyreport', '', 'smartyreport');

        $view_file = (string)$this->rephead->title['id'].'-'.(string)$this->viewinfo->smarty;
        
        Report::assign_for_smarty($this->designinfo, (string)$this->rephead->title);

        if ($mode===US_report_view_result::M_FILE) {
            $temp_file = Report_config::get_report_tmp_name(US_Reports::FILE_PREFIX_REPORT_TEMP);
            file_put_contents( $temp_file, $this->CI->smartyreport->process(false, $view_file, $this->file_name, true) );
            return $temp_file;
        } else {
            Report::set_header($this->viewinfo);
            $this->CI->smartyreport->process(false, $view_file, $this->file_name, false);
        }

    }

} // END class View_smarty
