KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Sending DateRangePicker selection to PDF Export #513

Open Andrew Froehlich opened this topic on on Nov 6, 2018 - 2 comments

Andrew Froehlich commented on Nov 6, 2018

It doesn't appear I can send an array as a hidden input to the Export to PDF. Can you guys give me some direction?

:: PostSummary.php

<?php
require_once $_SERVER['DOCUMENT_ROOT']."/koolreport/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;
    
class PostSummary extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\clients\Bootstrap;
    use \koolreport\export\Exportable;


    protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array(
                "2018-10-01",
                "2018-10-31"
            ),
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"=>"dateRange",
        );
    }
    
    
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "reports"=>array(
                    "connectionString"=>"mysql:host=hostname;dbname=reports",
                    "username"=>"username",
                    "password"=>"password",
                    "charset"=>"utf8"
                )
            )
        );
    }

    public function setup()
    {
        $this->src('reports')
        ->query("SELECT *
FROM (
  SELECT display_name, SUM(CASE WHEN post_type = 'page' THEN 1 ELSE 0 END) AS page_count,
	SUM(CASE WHEN post_type = 'post' AND site = 'GM Authority' THEN 1 ELSE 0 END) AS gma_post_count,
	SUM(CASE WHEN post_type = 'post' AND site IN ('Ford Authority','FC Authority') THEN 1 ELSE 0 END) AS alt_post_count,
	SUM(CASE WHEN post_type = 'post' THEN 1 ELSE 0 END) AS post_count, COUNT(*) AS count, 
	SUM(CASE WHEN HOUR(post_date) < 11 THEN 1 ELSE 0 END) AS by_noon, 
	SUM(CASE WHEN IFNULL(content_type,'news') = 'content' THEN 1 ELSE 0 END) AS content_count,
   month, year
  FROM posts_by_author
  WHERE post_date >= :start AND post_date <= :end
  GROUP BY display_name, month, year
) a
 LEFT OUTER JOIN (
  SELECT display_name, COUNT(*) AS edit_count
  FROM posts_by_editor
  WHERE post_date >= :start AND post_date <= :end
  GROUP BY display_name
) b USING(display_name)
 LEFT OUTER JOIN (
  SELECT display_name, COUNT(*) AS trans_count
  FROM posts_by_transcriber
  WHERE post_date >= :start AND post_date <= :end
  GROUP BY display_name
) c USING(display_name)
")
		->params(array(
            ":start"=>$this->params["dateRange"][0],
            ":end"=>$this->params["dateRange"][1]
        ))
        ->pipe($this->dataStore('reports'));
        
    }
}

:: PostSummary.view.php

<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\inputs\DateRangePicker;


include $_SERVER['DOCUMENT_ROOT']."/header.html";        
include $_SERVER['DOCUMENT_ROOT']."/nav.html";

?>
<div class="report-content">
    <div class="text-center">
        <h1>Post Summary</h1>
    </div>
    <form method="post">
        <div class="row">
            <div class="col-md-8 offset-md-2">
                <div class="form-group">
                <?php
                DateRangePicker::create(array(
                    "name"=>"dateRange"
                ))
                ?>
                </div>

                <div class="form-group text-center">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Load</button>
                    
                    <form method="post" action="export.php">
                    	<input type="hidden" value="<?php echo $this->params["dateRange"]; ?>" name="dateRange" />
                    	<button class="btn btn-primary">Download PDF</button>
                	</form>
                	
                </div>

            </div>
        </div>
    </form>
</div>    

<?php
/*
    BarChart::create(array(
        "dataStore"=>$this->dataStore('reports'),
        "width"=>"100%",
        "height"=>"500px",
        "columns"=>array(
            "display_name"=>array(
                "label"=>"Author"
            ),
            "count"=>array(
                "type"=>"number",
                "label"=>"Count",
            )
        ),
        "options"=>array(
            "title"=>"Posts by Author"
        )
    ));
*/
?>

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('reports'),
    	"showFooter"=>true,
        "columns"=>array(
            "display_name"=>array(
                "label"=>"Author Name",
                "footerText"=>"<b>Total</b>",
            ),
            "alt_post_count"=>array(
            	"label"=>"Alt Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            	/*
            	"formatValue"=>function($value,$row)
            	{
                	$color = $value>0?"#718c00":"#e83e8c";
                	
                	return "<span style='color:$color'>".number_format($value)."</span>";
            	}
            	*/
            ),
        
                    
            "gma_post_count"=>array(
            	"label"=>"GMA Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "post_count"=>array(
            	"label"=>"Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "page_count"=>array(
            	"label"=>"Page Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "count"=>array(
            	"label"=>"Total Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),           
        ),
    "cssClass"=>array(
        "table"=>"table-bordered table-striped table-hover"
    )
));


     
include $_SERVER['DOCUMENT_ROOT']."/footer.html";
?>

:: PostSummaryPdf.view.php

<?php 
    use \koolreport\widgets\koolphp\Table;


//include $_SERVER['DOCUMENT_ROOT']."/header.html";        
//include $_SERVER['DOCUMENT_ROOT']."/nav.html";

?>
<div class="report-content">
    <div class="text-center">
        <h1>Post Summary</h1>
    </div>

</div>

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('reports'),
    	"showFooter"=>true,
        "columns"=>array(
            "display_name"=>array(
                "label"=>"Author Name",
                "footerText"=>"<b>Total</b>",
            ),
            "alt_post_count"=>array(
            	"label"=>"Alt Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
        
                    
            "gma_post_count"=>array(
            	"label"=>"GMA Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "post_count"=>array(
            	"label"=>"Post Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "page_count"=>array(
            	"label"=>"Page Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),
            "count"=>array(
            	"label"=>"Total Count",
            	"footer"=>"sum",
            	"footerText"=>"<b>@value</b>",
            ),           
        ),
    "cssClass"=>array(
        "table"=>"table-bordered table-striped table-hover"
    )
));

?>

:: export.php

<?php
require_once "PostSummary.php";
$report = new PostSummary;

$report->run()
->export('PostSummaryPdf')
->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait",
))
->toBrowser("postSummary.pdf");
David Winterburn commented on Nov 6, 2018

Hi Andrew,

You don't need to use nested forms to submit export button to another page. Please remove both these inside form and hidden dateRange:

<form method="post" action="export.php">
                    	<input type="hidden" value="<?php echo $this->params["dateRange"]; ?>" name="dateRange" />

Then add the property "formaction" for the download button like this:

<button type="submit" formaction="export.php" class="btn btn-primary">Download PDF</button>

The dateRange input will still be submitted to export.php because it and the download button are inside the same form.

Please let us know if this works for you. Thanks!

Andrew Froehlich commented on Nov 8, 2018

That worked, thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None