I posted a while back asking if it would be easy enough to create a form where the client can choose a date range, and download sales reports etc. I’ve finally got round to doing it, and thought i would share the code on here:
Place this in an EE template. Please note i’ve used the Loop plugin to make it auto generate the dates / years. You will also need to change the URL in the ‘action’ parameter to point to your ‘download’ template.
<form method="post" action="http://www.website.com/index.php/reports/download">
<div style="border: 3px solid #F2F2F2; padding: 10px; margin: 10px;">
<strong>Start Date</strong><br><br>
<select name="start-day">
{exp:for_loop start="01" end="31" increment="1"}
<option value="{index}">{index}</option>
{/exp:for_loop}
</select>
<select name="start-month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="start-year">
{exp:for_loop start="2008" end="2015" increment="1"}
<option value="{index}" {if {loop_count} == 4}selected{/if}>{index}</option>
{/exp:for_loop}
</select>
</div>
<div style="border: 3px solid #F2F2F2; padding: 10px; margin: 10px;">
<strong>End Date</strong><br><br>
<select name="end-day">
{exp:for_loop start="01" end="31" increment="1"}
<option value="{index}">{index}</option>
{/exp:for_loop}
</select>
<select name="end-month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="end-year">
{exp:for_loop start="2008" end="2015" increment="1"}
<option value="{index}" {if {loop_count} == 4}selected{/if}>{index}</option>
{/exp:for_loop}
</select>
</div>
<div style="border: 3px solid aqua; padding: 10px; margin: 10px;">
<input type="submit" name="submit" value="Download" />
</div>
</form>
Then place the code below in a template named “download” or something similar. Enabling PHP and set the parsing to input. Please note i haven’t added the Excel code below, but its easy enough to add between the weblog tags.
<?php
$start_date = $_POST['start-year'].'-'.$_POST['start-month'].'-'.$_POST['start-day'];
$end_date = $_POST['end-year'].'-'.$_POST['end-month'].'-'.$_POST['end-day'];
?>
{exp:weblog:entries weblog="orders" orderby="date" limit="400" start_on="<?php echo $start_date; ?> 00:00" stop_before="<?php echo $end_date; ?> 23:59"}
{title} - ( {entry_date format="%Y %m %d"} )<br />
{/exp:weblog:entries}
----
<br>
Start - <?php echo $start_date; ?>
<br>
End - <?php echo $end_date; ?>
<br>
----
I’ve placed a bit of code at the bottom of that template so you can see if the PHP is outputting.
