How can I use session variables in a report created with the Forena module? I've installed Forena Reports. It's basically working, but I have some questions (see bottom of post to get right to it).

What I want to accomplish is the following

I want an anonymous user of the module page to be able to export their recommendations as a CSV file with a link like 'download now' or something.

Here's the staging environment for the tool I'm talking about, so you can see how it works: http://staging.grantstation-pathfinder.com/pathfinder.

So, as you can see, here's what I have so far

I have a custom module that's a multi-step form. The module prints out each page of the form. The user selects one option on each page (3 pages total) and on the final page submits the form. The module then redirects the user to a 'recommendations' page (page 4 - modulename/recommendations) where some custom SQL prints out to the page recommended resources for that user based on their selections in the form. 

The values the users select are saved in session variables.

Here's how those variables get stored as sessions in the form itself. (This is the second page of the form, but they are all basically the same.)

function pathfindertool_first_form($form, $form_state) {
 // .. some code, some other fields, directions, etc.
        '#default_value' =&gt; isset($values['role']) ? $values['role'] : NULL,
        '#options' =&gt; array(
        t('Grant Writer'),
        t('Nonprofit Administrator'),
        t('Nonprofit Founder'),
        t('Consultant'))
    );
      $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Next'),
      );
      return $form;
    }

    /**
     * Submit handler for the first form.
     *
     * @see pathfindertool_first_form() above
     */
     function pathfindertool_first_form_submit($form, &amp;$form_state) {
      $values = $form_state['values'];

      // Save values to the form storage, add the next step function callback
      $form_state['rebuild'] = TRUE; 
      $form_state['storage']['role'] = $values['role'];
      // submit code
    }


On the recommendations page I call SQL and use the session variables to determine which recommendations to display to users.

Here's how I set the session variables and redirect the users to the recommendation's page.

$form_state['storage']['topic'] = $values['topic'];
// set session variables to be used on recommendations page
$_SESSION['role'] = $form_state['storage']['role'];
$_SESSION['level'] = $form_state['storage']['level'];
$_SESSION['topic'] = $form_state['storage']['topic'];
// when user clicks 'submit' redirect them to recommendations page
$form_state['redirect'] = 'pathfinder/recommendations';


I successfully installed and configured the Forena module, and it displays my tabular data from the SQL file I created with the parameters I manually set. The CSV download works too. That's all fine.

How do I ensure the Forena modules uses the session variables set by the user in the multi-page form (and not my predefined parameters)?
I'm not (yet) sure about this one, because of the "session variables" that aren't clear enough to me (yet) ... Below are a few techniques (features) that you may want to consider to get it to work.

1. Using JavaScript and/or Skins

A possible solution "might" be to think of some technique you can implement via a JavaScript. And then make that JavaScript available via what in Forena is called "skins" (used for e.g. theming a report, like to enable the 'DataTables' plugin if you want, etc).

There are some "interesting" issues in the Forena issue queue with some great examples (ideas) of things you can do (add to Forena) via JavaScripts and/or Skins. HEre are a few of them:


Using the dataTables plugin to format reports, via an appropriate "skin".
Making table headers sticky, note the comments nr 8 (using Drupal Behaviours) and nr 10 (adding some JavaScript library).


2. Specifying Report Parameters as part of the URL

Report Parameters are similar to using arguments in Views. You can specify them as part of the URL, by first adding a ?-mark, followed by the name of the report parameter, a =-sign, and then the parameter value. So something like ?state=VA that you append to the report URL.

To see it at work in the demo site, try this example which uses ?state=VA (watch the URL of it also). Then change the end of the URL to something like ?state=IL,  ?state=CA, etc. To be complete, you can also specify multiple parameters (+their values) in an URL.

So if you have a way to massage those session variables in a such string added to the URL, then the answer to your question is something like "pass them as report parameters via the URL".

3. Other approaches

If what is above won't work, then please add more details about those "session variabes" (so that I can refine/rework my answer accordingly).

And if we don't find a real answer, then its time to experience the "support" that comes with Forena, via its issue queue on D.O. ... After all, keep in mind that I'm only a co-maintainer of this module. When I'm stuck (or out of Forena-inspiration), I escalate such questions/issues to David (the module owner and creator or Forena).