Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Export Users 4.0.x Solution
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 03-11-2007, 01:05 PM
 
speedworx speedworx is offline
 

Member
  
Join Date: Jan 2006
Posts: 10
 

Default Export Users 4.0.x Solution

I've poured through the forums here and have seen many requests for a method to export user information from within the administration interface. As I need this too, I developed a solution that is working for me in 4.0.17 - 4.0.19. There are a few steps but they're relatively simple to follow.

Step 1 - Add Language Variable (Administration > Languages > English >)
Variable: lbl_export_users
Value: Export Users

Step 2 - Create New Directories
your_xcart_dir/modules/Export_Users
your_xcart_dir/skin1/modules/Export_Users

Step 3 - Create Admin Wrapper File (your_xcart_dir/admin/export_users.php)
Complete file content:
Code:
<?php # # $Id: export_users.php,v 1.0.0.0 2007/03/10 07:41:48 tewald Exp $ # define('USE_TRUSTED_POST_VARIABLES',1); $trusted_post_variables = array("mode"); require "./auth.php"; require $xcart_dir."/include/security.php"; $location[] = array(func_get_langvar_by_name("lbl_export_users"), ""); include $xcart_dir."/modules/Export_Users/export_users.php"; $smarty->assign("main","export_users_admin"); # Assign the current location line $smarty->assign("location", $location); @include $xcart_dir."/modules/gold_display.php"; func_display("admin/home.tpl",$smarty); ?>

Step 4 - Create Admin Processing File (your_xcart_dir/modules/Export_Users/export_users.php)
Complete file content:
Code:
<?php # # $Id: export_users.php,v 1.22.2.11 2007/03/10 14:58:23 tewald Exp $ # if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); } if ($REQUEST_METHOD == "POST") { $users_data = func_query("SELECT CONCAT(firstname, \" \", lastname) AS fullname, company, b_address, b_city, b_state, b_zipcode, b_country, email, phone, fax FROM xcart_customers WHERE usertype LIKE 'C' ORDER BY fullname ASC"); if ($users_data) { $delimiter="\t"; if (!strncmp($export_fmt,"csv",3)) { header("Content-Type: application/csv"); header("Content-Disposition: attachment; filename=\"users_data.csv\""); switch($export_fmt) { case "csv_semi": $delimiter=";"; break; case "csv_comma": $delimiter=","; break; default: $delimiter="\t"; break; } } elseif (!strncmp($export_fmt,"xls",3)) { header("Content-Type: application/x-msdownload"); header("Content-Disposition: attachment; filename=\"users_data.xls\""); } else { header("Content-type: text/plain"); header("Content-disposition: attachment; filename=users_data.csv"); } $smarty->assign("delimiter", $delimiter); $_tmp_smarty_debug = $smarty->debugging; $smarty->debugging = false; $data .= "Full Name" . $delimiter; $data .= "Company" . $delimiter; $data .= "Address" . $delimiter; $data .= "City" . $delimiter; $data .= "State" . $delimiter; $data .= "Zip" . $delimiter; $data .= "Country" . $delimiter; $data .= "Email" . $delimiter; $data .= "Phone" . $delimiter; $data .= "Fax" . $delimiter; for ($row = 0; $row < sizeof($users_data); $row++) { $line = ''; while (list($key, $value) = each($users_data[$row])) { if ((!isset($value)) OR ($value == "")) { $value = $delimiter; } else { $value = str_replace('"', '""', $value); $value = str_replace("\r","",$value); $value = str_replace("\r\n","",$value); $value = trim($value); $value = '"' . $value . '"' . $delimiter; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); $data = str_replace("\r\n","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } $smarty->assign("data", $data); func_display("modules/Export_Users/users_export.tpl",$smarty); flush(); } $smarty->debugging = $_tmp_smarty_debug; exit; func_header_location($HTTP_REFERER); } ?>

Step 4 - Create Skin File 1 of 2 (your_xcart_dir/skin1/modules/Export_Users/export_users_admin.tpl)
Complete file content:
Code:
{* $Id: export_users_admin.tpl,v 1.40.2.5 2007/03/10 12:56:57 tewald Exp $ *} {include file="page_title.tpl" title=$lng.lbl_export_users} {capture name=dialog} <TABLE border="0" cellpadding="1" cellspacing="5"> <FORM name="export_users" action="export_users.php" method="POST"> <INPUT type="hidden" name="mode" value="export"> <TR> <TD width="20%" class="FormButton" nowrap>{$lng.lbl_export_file_format}:</TD> <TD width="10">&nbsp;</TD> <TD width="80%"> <SELECT name="export_fmt"> <OPTION value="xls_tab"{if $search_prefilled.export_fmt eq "xls_tab"} selected{/if}>XLS</OPTION> <OPTION value="csv_tab"{if $search_prefilled.export_fmt eq "csv_tab"} selected{/if}>CSV {$lng.lbl_with_tab_delimiter}</OPTION> <OPTION value="csv_semi"{if $search_prefilled.export_fmt eq "csv_semi"} selected{/if}>CSV {$lng.lbl_with_semicolon_delimiter}</OPTION> <OPTION value="csv_comma"{if $search_prefilled.export_fmt eq "csv_comma"} selected{/if}>CSV {$lng.lbl_with_comma_delimiter}</OPTION> </SELECT> <INPUT type="button" value="{$lng.lbl_export_all}" onclick="document.export_users.mode.value='export_all'; document.export_users.submit();"> </TD> </TR> </FORM> </TABLE> {/capture} {include file="dialog.tpl" title=$lng.lbl_export_users content=$smarty.capture.dialog extra="width=100%"}

Step 5 - Create Skin File 2 of 2 (your_xcart_dir/skin1/modules/users_export.tpl)
Complete file content:
Code:
{* $Id: users_export.tpl,v 1.10.2.1 2007/03/10 06:20:27 tewald Exp $ *} {$data}

Step 6 - Add Export Users Link to Admin Menu
Modify your_xcart_dir/skin1/admin/menu.tpl:
Add:
Code:
<A href="{$catalogs.admin}/export_users.php" class="VertMenuItems">{$lng.lbl_export_users}</A><BR>
After:
Code:
<A href="{$catalogs.admin}/users.php" class="VertMenuItems">{$lng.lbl_users}</A><BR>

Step 7 - Add Export Interface
Modify your_xcart_dir/skin1/single/home.tpl:
Add:
Code:
{* START EXPORT USERS ADMIN *} {elseif $main eq "export_users_admin"} {include file="modules/Export_Users/export_users_admin.tpl"} {* END EXPORT USERS ADMIN *}
After:
Code:
{elseif $main eq "general_info"} {include file="admin/main/general.tpl"}

Notes:
1. This only exports the usertype of Customer (not Admins or Providers). If you want to change this, just modify the SQL statement in your_xcart_dir/modules/Export_Users/export_users.php. For example, you can remove the "WHERE usertype LIKE 'C'" to get all users.
2. If you want to add/remove exported fields, modify the SQL statement in your_xcart_dir/modules/Export_Users/export_users.php AND add/remove lines in the same file from the section containing code like:
$data .= "Company" . $delimiter;
Just remember if you add a field, add a line and vice versa for deleting. The last line though must have the newline character ( i.e. $data .= "Fax" . $delimiter . "\n"; ).

Well, that's it for my first posted mod. I hope it helps as I've received great assistance from this forum as well.
__________________
XCart4.0.19
Reply With Quote
  #2  
Old 03-24-2007, 03:05 PM
 
smrtsu smrtsu is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 34
 

Default Re: Export Users 4.0.x Solution

Thanks for creating this mod - I just had a client ask me for this feature. There are a couple of minor tweaks, basically just inconsistencies in the instructions:

Quote:
Originally Posted by speedworx
Step 1 - Add Language Variable (Administration > Languages > English >)
Variable: lbl_export_users_title
Should read: Variable: lbl_export_users

Quote:
Originally Posted by speedworx
Step 4 - Create Skin File 1 of 2 (your_xcart_dir/skin1/modules/export_users_admin.tpl)
Should read: Step 4 - Create Skin File 1 of 2 (your_xcart_dir/skin1/modules/Export_Users/export_users_admin.tpl)


Otherwise, works great!
__________________
smrtsu
xcart v4.0.17 http://www.ettasays.com
xcart v4.0.19 http://www.inspa.com
Reply With Quote
  #3  
Old 03-24-2007, 03:29 PM
 
speedworx speedworx is offline
 

Member
  
Join Date: Jan 2006
Posts: 10
 

Default Re: Export Users 4.0.x Solution

Good catches on the steps - thanks smrtsu. I've updated my first post to include your edits. I'm glad it was of help too.
__________________
XCart4.0.19
Reply With Quote
  #4  
Old 03-24-2007, 03:32 PM
 
smrtsu smrtsu is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 34
 

Default Re: Export Users 4.0.x Solution

It's the curse of being an instructional designer
__________________
smrtsu
xcart v4.0.17 http://www.ettasays.com
xcart v4.0.19 http://www.inspa.com
Reply With Quote
  #5  
Old 05-06-2008, 12:32 PM
 
fb-guy fb-guy is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 64
 

Default Re: Export Users 4.0.x Solution

Hello all,

I wanted to check in a see how this mod is working for folks. We want to export about 13,000 customer names and email addresses to allow for import into Constant Contact. We've decided to give our email newsletter management to service provider, rather than run it through our service provider.

Is this the best way to tackle the customer export requirement?

Thanks.
FB
__________________
X-Cart Gold 4.0.17
DSEFU
BCSE Product Keywords
Fed Ex Label Mod
X-Cart Affiliate
Altered Cart On Sale
User Export Mod
Marketing Manager Pro

Pizza Peel
Outdoor Fireplaces
Reply With Quote
  #6  
Old 05-07-2008, 03:00 PM
 
fb-guy fb-guy is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 64
 

Default Re: Export Users 4.0.x Solution

Hello again,

I am installing the mod and have encountered this error. I will try to see what I did wrong, but does anyone have an idea. Thanks.

FB

<b>Warning</b>: Smarty error: unable to read resource: "modules/Export_Users/users_export.tpl" in <b>/home/store-directory/Smarty-2.6.9/Smarty.class.php</b> on line <b>1088</b><br />
__________________
X-Cart Gold 4.0.17
DSEFU
BCSE Product Keywords
Fed Ex Label Mod
X-Cart Affiliate
Altered Cart On Sale
User Export Mod
Marketing Manager Pro

Pizza Peel
Outdoor Fireplaces
Reply With Quote
  #7  
Old 05-14-2008, 05:00 PM
 
fb-guy fb-guy is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 64
 

Default Re: Export Users 4.0.x Solution

Help!

Any ideas here?
Thanks,
FB
__________________
X-Cart Gold 4.0.17
DSEFU
BCSE Product Keywords
Fed Ex Label Mod
X-Cart Affiliate
Altered Cart On Sale
User Export Mod
Marketing Manager Pro

Pizza Peel
Outdoor Fireplaces
Reply With Quote
  #8  
Old 05-22-2008, 08:50 PM
 
intel352 intel352 is offline
 

X-Wizard
  
Join Date: Dec 2005
Posts: 1,071
 

Default Re: Export Users 4.0.x Solution

The instructions have an error, move this file:
skin1/modules/users_export.tpl
to this location:
skin1/modules/Export_Users/users_export.tpl

Quote:
Originally Posted by fb-guy
Hello again,

I am installing the mod and have encountered this error. I will try to see what I did wrong, but does anyone have an idea. Thanks.

FB

<b>Warning</b>: Smarty error: unable to read resource: "modules/Export_Users/users_export.tpl" in <b>/home/store-directory/Smarty-2.6.9/Smarty.class.php</b> on line <b>1088</b><br />
__________________
-Jon Langevin
WARNING: Unethical developer - NOT RECOMMENDED
See details here
Reply With Quote
  #9  
Old 05-22-2008, 09:23 PM
 
fb-guy fb-guy is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 64
 

Default Re: Export Users 4.0.x Solution

Thanks. I finally caught that -- I should have said something.
FB
__________________
X-Cart Gold 4.0.17
DSEFU
BCSE Product Keywords
Fed Ex Label Mod
X-Cart Affiliate
Altered Cart On Sale
User Export Mod
Marketing Manager Pro

Pizza Peel
Outdoor Fireplaces
Reply With Quote
  #10  
Old 05-29-2008, 10:59 AM
 
BrighterBlooms1 BrighterBlooms1 is offline
 

Advanced Member
  
Join Date: Feb 2008
Location: Charlotte, NC
Posts: 29
 

Default Re: Export Users 4.0.x Solution

I too have installed this error, when i try to open the .xls file i get an error that says "unable to read" and when i try to export to a .csv, it goes to a blank screen. any ideas?
__________________
X-cart version 4.6.5
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:56 AM.

   

 
X-Cart forums © 2001-2020