Embedding Reportico

In order to place a fully functional report within your own web pages you need to include code similar to the contents of the run.php within your script. It is necessary therefore to include reportico by including the reportico's composer autoloader as shown below. When embedding you probably also want to customise how Reportico appears to the user. For example you may want to include a single report output within a div, or include a single graph within a div or give the user the ability to enter criteria for a single report and execute it. You may want to give user access to a single report suite but disallow entry to report menus.

Examples of embedding can be found in the supplied examples folder.

You can also use any of the parameters found in the run.php for configuring your page.

An example web page may look as follows, which embeds report output into a web page :

    <HTML>
      <BODY>

          ...... Your web content ...... 

          <!-- Start of Reportico Report -->
          <?php
          
            // Important lines to tell your web pge how to access Reportico, you need the next 6 lines
            require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
            $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
            $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
            $q = new Reportico\Engine\Reportico(); 
            $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
            $q->url_path_to_assets = $reportico_url_home."/assets";
            $q->url_path_to_templates = $reportico_url_home."/themes";

            // Set the theme, project and report to run
            $q->setTheme('default');
            $q->access_mode= "ONEREPORT";     
            $q->initial_execute_mode= "EXECUTE";
            $q->initial_project = "tutorials"; 
            $q->initial_report= "stock";
            $q->initial_output_format = "HTML";                 
            $q->execute();
          ?> 
          < !-- End of Reportico Report -->

          ...... More web content ......

      </BODY>
    </HTML>

Using a combination of the initial_execute_mode and access_mode properties, it is possible to take a user to a specific report or specific report menu to execute report, execute a report to show just the graphs, just the report detail or just the group headers, for example. When generating report out you have control whether the user has a return button to go back to criteria entry.

initial_execute_mode indicates what type of screen user is first taken into. Valid values for initial_execute_mode are ADMIN, MENU, PREPARE or EXECUTE. ADMIN takes user to the ADMIN page, MENU takes user to a report menu ( an initial project must be specifiedd ), PREPARE takes user to the criteria entry screen of a specfic report ( project and report must be specified ) and EXECUTE runs a specified report ( project and report must be specified ).

Allow using the properties initial_project and initial_report take users directly to the specified report suite and report files respectively. If a project is controlled by a password this can be provided in the initial_project_password so the user doesnt have to type the password in.

access_mode indicates what Reportico pages and functions a user has access to. Valid options are

FULL

provides access to the Admin Page and the ability to enter Design mode, if users give the correct Admin password

ALLPROJECTS

users can use admin page to select a project (but not be able to enter admin mode). Users can select and run reports and navigate between report output, report criteria and the report project menu where users can choose a report to run. Dropdown menus ( see documentation ) can be used to swap between project reports and projects if required

ONEPROJECT

users can use a single project, select and run reports and navigate between report output, report criteria and the report project menu where users can choose a report to run. Swapping between project menus in rhis mode must also be down by a dropdown menu (see documentation for how to do this)

ONEREPORT

user gets access to a single report's criteria entry mode and can run the report and then jump back to criteria entry again

REPORTOUTPUT

the output of a single report is presented and the user may not navigate to any other Reportico page

Example 1 - Run a single report salesforecast,xml in project sales (which is password protected with password “password” and run to HTML output.

   <HTML>
      <BODY>

          ...... Your web content ...... 

          <!-- Start of Reportico Report -->
          <?php
            require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
            $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
            $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
            $q = new Reportico\Engine\Reportico(); 
            $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
            $q->url_path_to_assets = $reportico_url_home."/assets";
            $q->url_path_to_templates = $reportico_url_home."/themes";
            
            $q->initial_project = "sales";
            $q->initial_project_password = "password";
            $q->initial_report = "salesforecast.xml";
            $q->initial_execute_mode = "EXECUTE";
            $q->initial_output_format = "HTML";
            $q->access_mode = "REPORTOUTPUT";
            $q->embedded_report = true;
            $q->execute();
          ?> 
          < !-- End of Reportico Report -->

          ...... More web content ......

      </BODY>
    </HTML>

Example 2 - Run the menu for project “stock” with no access to menu

    <HTML>
      <BODY>

          ...... Your web content ...... 

          <!-- Start of Reportico Report -->
          <?php
            require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
            $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
            $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
            $q = new Reportico\Engine\Reportico(); 
            $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
            $q->url_path_to_assets = $reportico_url_home."/assets";
            $q->url_path_to_templates = $reportico_url_home."/themes";
            
            $q->initial_project = "stock";
            $q->initial_project_password = "password";
            $q->initial_execute_mode = "MENU";
            $q->access_mode = "SINGLEPROJECT";
            $q->embedded_report = true;
            $q->execute();
          ?> 
          < !-- End of Reportico Report -->

          ...... More web content ......

      </BODY>
    </HTML>

When running reportico from an embedded page or via custom scripts it is possible to avoid the need to write a report and just give Reportico the SQL. This is possible in two ways:

Option 1 - Use the initial_sql parameter and the initial_project parameter. Note that the column aliases are useful to provide more meaning ful column titles ( other column titles will be derived by changing any underscores to spaces and having word initial letters capitalized.

   <HTML>
      <BODY>

          ...... Your web content ...... 

          <!-- Start of Reportico Report -->
          <?php
            require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
            $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
            $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
            $q = new Reportico\Engine\Reportico(); 
            $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
            $q->url_path_to_assets = $reportico_url_home."/assets";
            $q->url_path_to_templates = $reportico_url_home."/themes";
            
            $q->initial_project_password = "password"; // If required
            $q->initial_sql = "SELECT column1 AS columntitle1, column2 AS columntitle2, expression() as columntitle3 FROM table";
            $q->initial_output_format = "HTML";
            $q->access_mode = "REPORTOUTPUT";
            $q->embedded_report = true;
            $q->execute();
          ?> 
          < !-- End of Reportico Report -->

          ...... More web content ......

      </BODY>
    </HTML>

Option 2 - use the importSQL feature - this provides extra customisation features which will be documented later ( the idea being to be able to programatically build a report from scratch).

    <HTML>
      <BODY>

          ...... Your web content ...... 

          <!-- Start of Reportico Report -->
          <?php
            require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
            $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
            $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
            $q = new Reportico\Engine\Reportico(); 
            $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
            $q->url_path_to_assets = $reportico_url_home."/assets";
            $q->url_path_to_templates = $reportico_url_home."/themes";
            
            $q->initial_project = "stock";
            $q->initial_project_password = "password"; // if required
            $q->importSQL("SELECT column1 AS columntitle1, column2 AS columntitle2 FROM table";
            $q->get_column("column1")->set_attribute("column_display","hide");
            $q->get_column("column1")->set_attribute("column_title","Custom Title");
            $q->set_attribute("ReportTitle","New Report Title");

            $q->embedded_report = true;
            $q->execute();
          ?> 
          < !-- End of Reportico Report -->

          ...... More web content ......

      </BODY>
    </HTML>

When directly taking a user to report output or criteria entry you can control certain output features.

To control whether output is provided in HTML, PDF, CSV, XML or JSON format just set the initial_output_format property to HTML, PDF, CSV, XML or JSON respectively For example :-

            $q->initial_output_format = "PDF";

To control whether output shows or hides the report detail/graphs, criteria etc …

            $q->initial_show_detail = "hide";
            $q->initial_show_graph = "show";
            $q->initial_show_group_headers = "hide";
            $q->initial_show_group_trailers = "hide";
            $q->initial_show_column_headers = "hide";
            $q->initial_show_criteria = "hide";

To control whether reports are generated as a single line per report output in multi-column format or a page of data with one line per column value, set the initial_output_style to either TABLE or FORM, e.g.

    $q->initial_output_style = "FORM";

To provide a refresh button set the following :-

    $q->show_refresh_button = true;

Reportico by default is styled according to Bootstrap 3, a copy of which is supplied with Reportico, which Reportico loads up. However when embedding into a web page this may not be desirable. If your web page is not compatible with Bootstrap then you can revert to Reportico Classic styling by setting bootstrap_styles = false. If your web pages already have Bootstrap 3 loaded then set bootstrap styles to “3” and set bootstrap_preloaded. If your site has bootstrap 2 then set this to “2”.

        $q->bootstrap_styles = "3"; // Set to false for reportico classic, or 2 to use bootstrap 2 styling conventions
        $q->bootstrap_preloaded = false; // Set to true to use existing site bootstrap

One way of passing parameters reports is to use the “MANUAL_” method mechanism of passing parameters within the $_REQUEST record. A better way when embedding reportico or generating custom reportico scritps is to use the initial_execution_parameters array property. Just biuld this array up with the key of the criteria name ( as specified in the report criteria definitions ) and the criteria value you want used witihn the report query. For date ranges use the “-” notation and for multiple options for a list or lookup type criteria specify the values with comma separated values.

The following example runs a report for specified countries and covers the dates between the start of 2013 and today :-

            $q->initial_execution_parameters = array();
            $q->initial_execution_parameters["country"] = "Italy,Australia";
            $q->initial_execution_parameters["invoice_dates"] = "2013-01-01-TODAY";
            $q->execute();

Reportico can be embedded into PHP frameworks and CMS. In this case you may want to use the database connection settings from the framework rather than having to specify them again in your project definition. To achieve this, when you create to configure your project, you need to choose the “framework” database driver option. Then in your calling script, before the Reportico execute() call, you need to specify the following databse constants ( quite often CMSs or frameworks provide functions to access these values :-

    define('SW_FRAMEWORK_DB_DRIVER','<DATABASETYPE>'); e.g. pdo_mysql, pdo_pgsql, pdo_mssql etc
    define('SW_FRAMEWORK_DB_USER', $myframework->getuser());
    define('SW_FRAMEWORK_DB_PASSWORD',$myframework->getPassword());
    define('SW_FRAMEWORK_DB_HOST',$myframework->getHostName()); // Use ip:port to specifiy a non standard port
    define('SW_FRAMEWORK_DB_DATABASE',$myframework->getDatabase());
    $q->execute();

AJAX mode is turned on by default. In AJAX mode, all button presses are made as an AJAX call meaning that there is no full page refresh performed. This makes its operation look nicer when embedded in complex web pages. It also allows it to work alongside other web apps in a page.

To include reportico in this fashion you need to set a Reportico property alongside the other paramters. Just set For example :-

    $q->reportico_ajax_mode = true;

You can turn on dynamic sortable, searchable, pageable grids with the following parameters -

    $q->dynamic_grids = true;
    $q->dynamic_grids_sortable = true;
    $q->dynamic_grids_searchable = true;
    $q->dynamic_grids_paging = false;
    $q->dynamic_grids_page_size = 10;

When embedding it is easier to specify the menu items available to the user both in the dropdown control panel at the top and in the front end menu page. Just set up the following arrays :-

    // Static - main menu definition
    $q->static_menu = array (
	    array ( "report" => "an_xml_reportfile1", "title" => "<AUTO>" ),
	    array ( "report" => "another_reportfile", "title" => "<AUTO>" ),
	    array ( "report" => "", "title" => "BLANKLINE" ),
	    array ( "report" => "anotherfreportfile", "title" => "Custom Title" ),
	    array ( "report" => "", "title" => "BLANKLINE" ),
	    array ( "report" => "andanother", "title" => "Another Custom Title" ),
	);

    // To auto generate a static menu from all the xml report files in the project use
    $q->static_menu = array ( array ( "report" => ".*\.xml", "title" => "<AUTO>" ) );
    
    // To hide the static report menu
    $q->static_menu = array ();

    // Dropdown Menu definition
    $q->dropdown_menu = array(
                    array ( 
                        "project" => "projectname",
                        "title" => "dropdown menu 1 title",
                        "items" => array (
                            array ( "reportfile" => "report" ),
                            array ( "reportfile" => "anotherreport" ),
                            )
                        ),
                    array ( 
                        "project" => "projectname",
                        "title" => "dropdown menu 2 title",
                        "items" => array (
                            array ( "reportfile" => "report" ),
                            array ( "reportfile" => "anotherreport" ),
                            )
                        ),
                );

It is possible to turn off the report output title, some of the control panel buttons and checkboxes in crtieria entry mode and some of the the menus by setting any of the following to “hide”

    $q->output_template_parameters["show_hide_navigation_menu"] = "show";
    $q->output_template_parameters["show_hide_dropdown_menu"] = "show";
    $q->output_template_parameters["show_hide_report_output_title"] = "show";
    $q->output_template_parameters["show_hide_prepare_section_boxes"] = "show";
    $q->output_template_parameters["show_hide_prepare_pdf_button"] = "show";
    $q->output_template_parameters["show_hide_prepare_html_button"] = "show";
    $q->output_template_parameters["show_hide_prepare_print_html_button"] = "show";
    $q->output_template_parameters["show_hide_prepare_csv_button"] = "show";
    $q->output_template_parameters["show_hide_prepare_page_style"] = "show";

One way of passing parameters reports is to use the “MANUAL_” method mechanism of passing parameters within the $_REQUEST record. A better way when embedding reportico or generating custom reportico scritps is to use the initial_execution_parameters array property. Just biuld this array up with the key of the criteria name ( as specified in the report criteria definitions ) and the criteria value you want used witihn the report query. For date ranges use the “-” notation and for multiple options for a list or lookup type criteria specify the values with comma separated values.

The following example runs a report for specified countries and covers the dates between the start of 2013 and today :-

            $q->initial_execution_parameters = array();
            $q->initial_execution_parameters["country"] = "Italy,Australia";
            $q->initial_execution_parameters["invoice_dates"] = "2013-01-01-TODAY";
            $q->execute();

It is possible to embedded reportico so that it generates several instances on a single page. You could for example chain report output together or use the hide and show options to run several reports with graphs to present only the graphs in a kind of dashboard.

To do this you need to use the namespace property to ensure that successive embedded reports do not get their sessions confused. You also need to create a new instance of reportico for each successive report to avoid other conflicts.

Note that reportico_ajax_mode is set to true. If you want to allow the user to interact wih more than one report on a page ( enter criteria, select from menus ) then you need this option to avoid full screen refreshes.

Note that currently you cannot chain together reports from different projects, this will be addressed in a future release.

This example chains together two reports in graph mode, note the use of the namespace property :-

    require '{FULL_PATH_TO_REPORTICO}/vendor/autoload.php'; // SET THIS!
    $reportico_home = "/{path_on_disk_to_reportico}/";      // SET THIS!
    $reportico_url_home = "http://{url_path_to_reportico}"; // SET THIS!
            
    // Run first report
    $q = new Reportico\Engine\Reportico(); 
    $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
    $q->url_path_to_assets = $reportico_url_home."/assets";
    $q->url_path_to_templates = $reportico_url_home."/themes";
    
    $q->initial_project = "myproject";
    $q->initial_project_password = "password";
    $q->initial_report = "graph1.xml";
    $q->initial_execute_mode = "EXECUTE";
    $q->initial_show_detail = "hide";
    $q->initial_show_graph = "show";
    $q->initial_show_group_headers = "hide";
    $q->initial_show_group_trailers = "hide";
    $q->initial_show_column_headers = "hide";
    $q->initial_show_criteria = "hide";
    $q->access_mode = "REPORTOUTPUT";
    $q->embedded_report = true;
    $q->session_namespace = "GRAPH1";
    $q->show_refresh_button = true;
    $q->execute();

    // Run second report
    $q = new Reportico\Engine\Reportico(); 
    $q->reportico_ajax_script_url = $reportico_url_home."/run.php";
    $q->url_path_to_assets = $reportico_url_home."/assets";
    $q->url_path_to_templates = $reportico_url_home."/themes";
    $q->allow_debug = true;
    $q->reportico_ajax_mode = true;
    $q->initial_project = "myproject";
    $q->initial_project_password = "password";
    $q->initial_report = "graph2.xml";
    $q->initial_execute_mode = "EXECUTE";
    $q->initial_show_detail = "hide";
    $q->initial_show_graph = "show";
    $q->initial_show_group_headers = "hide";
    $q->initial_show_group_trailers = "hide";
    $q->initial_show_column_headers = "hide";
    $q->initial_show_criteria = "hide";
    $q->access_mode = "REPORTOUTPUT";
    $q->embedded_report = true;
    $q->session_namespace = "GRAPH2";
    $q->show_refresh_button = true;
    $q->execute();

If you want to pick up external system parameters such session variables or constants in tour reports you can set them in the main run.php or your own calling script. For example you might want to pass a user name,a user role or a site id. Just pass in

    $q->user_parameters["your_parameter_name"] = "your parameter value";

Then you can pick up in Reportico SQL queries using the construct {USER_PARAM,your_parameter_name}.

Quite often you want to produce reports that show records relevant to the logged in user. This is especially relevant to an embedded solution. To do this you need to provide the currently logged on user in the external_user property. Then to make use of the user in your queries use the {FRAMEWORK_USER} notation. For example in your calling script put :-

            $q->external_user = $user;
            $q->execute();

Then you can pick up in Reportico SQL queries using the construct {FRAMEWORK_USER} e.g..

            SELECT x 
            FROM y
            WHERE 1 = 1
            AND userid = {FRAMEWORK_USER}
            <code>
  • embedding_reportico.txt
  • Last modified: 2018/12/31 14:50
  • by admin