Page 1 of 1
Showing Template
Posted: Fri Feb 01, 2008 9:40 pm
by ross2376
I have an action in my module (action.ExportExcel.php) to export a list of contacts from DB to excel...as the name implies. The problem is this: The excel sheet gets exported (downloaded) with the entire template of the template. How do I make CMSMS not display the template for this specific admin action?
Re: Showing Template
Posted: Sat Feb 02, 2008 12:02 am
by Duketown
ross2376,
Not quite clear to me what you mean with
entire template of the template
. I take it that you do something like:
Retrieve a row from the database;
Format its fields by catenating them with delimiters;
Write the formated row to a .csv file (not sure if this would be on the server or for example on your c:\ drive);
Close the .csv file;
Open .csv using Excel.
Please provide us with the steps taken.
Maybe action.exportquiz.php from the module Quizzard can be of help.
Re: Showing Template
Posted: Mon Feb 04, 2008 2:54 pm
by ross2376
Code: Select all
if (!isset($gCms))
exit;
# Assign smarty variable by reference for easier use and cleaner code
$Smarty =& $this->smarty;
# Check appropriate user permissions
if (!$this->CheckPermission($this->Lang('PermissionExport')))
header('Location: http://' . $_SERVER['SERVER_NAME'] . '/admin');
# Generate administrative navigation
$this->DisplayAdminNav($id, $params, $returnid);
# Clean output buffers
@ob_clean();
@ob_clean();
# Send headers to identify as excel document
header('Content-type: application/vnd.ms-excel; name=\'excel\'');
header('Content-Disposition: attachment; filename=Contacts.xls');
header('Pragma: no-cache');
header('Expires: 0');
# Retrieve array of contact objects
$Contacts = $this->GetContact();
# Perform misc operations to ready data for listing
foreach ($Contacts AS $key => $value)
$Contacts[$key]->Date = date('F j, Y g:i A', $Contacts[$key]->Date);
$Smarty->Assign('Contacts', $Contacts);
# Display Template
echo $this->ProcessTemplate('ExportExcel.tpl');
# Exit application
exit;
I just want it to export these contacts to Excel...which it will do. The only problem is the excel sheet shows the entire CMS admin template (menus..footers...etc) with it instead of just my ExportExcel.tpl template. I thought about just making a standalone script that doesnt use a CMS module action but thats tacky in my mind. How do I make this action not load the global template?
Re: Showing Template
Posted: Mon Feb 04, 2008 8:42 pm
by alby
ross2376 wrote:
I thought about just making a standalone script that doesnt use a CMS module action but thats tacky in my mind. How do I make this action not load the global template?
View Printing module and PDF creation (createpdf.php)
Alby
Re: Showing Template
Posted: Mon Feb 04, 2008 9:37 pm
by ross2376
Thanks. I looked that up and I found the ContentPostRender() method to control content posting, however, this seems to only be valid for the frontend? My action is an admin action. How can I control admin content?
Re: Showing Template
Posted: Mon Feb 04, 2008 9:39 pm
by calguy1000
the link to your action should have 'showtemplate=false' as one of the parameters.
See how the Uploads module, and other similar modules (modules that send files).
Re: Showing Template
Posted: Mon Feb 04, 2008 9:55 pm
by ross2376
Code: Select all
$ExportLink = $this->CreateLink($id, 'ExportExcel', $returnid, 'here', array('showtemplate' => 'false'));
Is that correct?
If so, that didn't work for me.
Re: Showing Template
Posted: Wed Feb 06, 2008 2:23 pm
by ross2376
Anyone??