From: Jason Woofenden Date: Tue, 28 Aug 2012 09:34:31 +0000 (-0400) Subject: metaform: add csv download link to listings X-Git-Url: https://jasonwoof.com/gitweb/?a=commitdiff_plain;ds=inline;h=5e7ba7c884bd114678e6308a7447e646dee7f838;p=wfpl.git metaform: add csv download link to listings --- diff --git a/metaform/template.html b/metaform/template.html index 89f850a..ef08ba2 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -140,6 +140,7 @@ +

Download as CSV file

No ~plural~ in database.

diff --git a/metaform/template.php b/metaform/template.php index 6479fc5..0f3acf8 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -117,6 +117,10 @@ function ~file_name~_main() {~opt_pass {~ return ~file_name~_main_display($id); } ~}~~opt_listing {~ + if(_REQUEST_cut('download_csv')) { + return ~file_name~_csv_download(); + } + if(isset($_POST['~always_field~'])) { return ~file_name~_main_form(); } @@ -142,6 +146,13 @@ function ~file_name~_main_delete($id) { return './~file_name~'; }~}~~opt_listing {~ +function ~file_name~_csv_download() { + require_once('code/wfpl/csv.php'); + $rows = db_get_rows('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'order by id'); + array_unshift($rows, explode(',',~file_name upper~_DB_FIELDS)); + array2d_to_csv_download($rows, '~file_name~.csv'); +} + function ~file_name~_main_listing() { $data = array(); $desc = '';