<?php

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

class AdvancedReports_List_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_listview();

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

        $smarty->view('ReportViewer/main.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());
        // Post process ans show foooter
        parent::postProcess($request);
    }
}

}else{
class AdvancedReports_List_View extends Vtiger_Index_View{

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

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

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

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

    // #4047 [start] - Added custom footer
    public function postProcess(Vtiger_Request $request) {
        $moduleName = $request->getModule();
        $viewer = $this->viewer;
        $currentUser = Users_Record_Model::getCurrentUserModel();
        $viewer->assign('ACTIVITY_REMINDER', $currentUser->getCurrentUserActivityReminderInSeconds());

        // #5448 - Remove jQuery UI 1.8.16 which was making conflicts with $.ui.widget and other modules
        global $root_directory;
        $template = file_get_contents($root_directory . '/layouts/vlayout/' . vtemplate_path(false) . '/JSResources.tpl');
        $template = str_replace('<script type="text/javascript" src="libraries/jquery/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>', '', $template);
        $viewer->assign('JSRESOURCES', $viewer->fetch('string:' . $template));

        // Define custom footer for right javascripts
        $viewer->view('ReportViewer/Footer.tpl', $moduleName);
    }
    // #4047 [end]

}
}