<?php

global $vtiger_current_version;
if (version_compare($vtiger_current_version, '7.0.0', '>=')) {

class AdvancedReports_Report_View extends Vtiger_Index_View{

    protected $record = false;

    public function preProcess(Vtiger_Request $request, $display = true) 
    {
        $viewer = $this->getViewer($request);
        $moduleName = $request->getModule();

        $viewer->assign('MODULE_NAME', $moduleName);

        parent::preProcess($request, true);
    }

    public function preProcessTplName(Vtiger_Request $request) 
    {
        return 'DetailViewPreProcess.tpl';
    }

    public function process(Vtiger_Request $request) 
    {
        $moduleName = $request->getModule();
        $smarty = $this->getViewer($request);

        include "modules/AdvancedReports/controller.php";
        $controller = new AdvancedReportsController();
        $controller->action_report();

        foreach($controller->view_object_map as $key => $value) {
            $smarty->assign($key, $value);
        }

        $smarty->view('ReportViewer/report.tpl', $moduleName);
    }

    public function postProcess(Vtiger_Request $request) 
    {
        $moduleName = $request->getModule();
        $viewer = $this->viewer;
        $currentUser = Users_Record_Model::getCurrentUserModel();
        $viewer->assign('ACTIVITY_REMINDER', $currentUser->getCurrentUserActivityReminderInSeconds());

        $viewer->view('DetailViewPostProcess.tpl', $moduleName);

        // Post process ans show foooter
        parent::postProcess($request);
    }

    /**
     * Function to get the list of Script models to be included
     * @param Vtiger_Request $request
     * @return <Array> - List of Vtiger_JsScript_Model instances
     */
    public function getHeaderScripts(Vtiger_Request $request) {
        $headerScriptInstances = parent::getHeaderScripts($request);
        $moduleName = $request->getModule();

        $jsFileNames = array(
            "modules.$moduleName.resources.Report",
        );

        $jsScriptInstances = $this->checkAndConvertJsScripts($jsFileNames);
        $headerScriptInstances = array_merge($headerScriptInstances, $jsScriptInstances);
        return $headerScriptInstances;
    }

}
} else {
class AdvancedReports_Report_View extends AdvancedReports_List_View{
    public function process(Vtiger_Request $request) {
        $moduleName = $request->getModule();
        $smarty = $this->getViewer($request);

        include "modules/AdvancedReports/controller.php";
        $controller = new AdvancedReportsController();
        $controller->action_report();

        foreach($controller->view_object_map as $key => $value) {
            $smarty->assign($key, $value);
        }

        $smarty->view('ReportViewer/report.tpl', $moduleName);
    }
}
}