これはコードの一部です:
$toExport = array(
array('c.id_customer','"[quickid]"'),
array('c.firstname','"[name]"'),
array('c.lastname','"[lastname]"'),
array('c.siret','"[hej]"'),
array('c.email','"[email]"'),
);
c.firstname と c.lastname を [name] にマージしたいのですが、それが正しい用語ですか? このようなもの:
$toExport = array(
array('c.id_customer','"[quickid]"'),
array('c.firstname + c.lastname','"[name]"'),
array('c.siret','"[hej]"'),
array('c.email','"[email]"'),
);
最後のコードが非常に間違っていることは知っていますが、それは可能ですか?
ここにコード全体があります:
Content-Type:text/html; charset=utf-8
<?php
mb_internal_encoding("UTF-8");
class ExportCustomers extends Module
{
function __construct()
{
$this->name = 'exportcustomers';
$this->tab = 'Export';
$this->version = "1.2";
$this->author = 'Madman'; //. Based on Willem's module';
parent::__construct();
$this->displayName = $this->l('Export customers');
$this->description = $this->l('Module for export customers to xls file.');
}
function install()
{
if (!parent::install())
return false;
return true;
}
function getContent()
{
$this->_html = '<hr><h2>'.$this->displayName.'</h2>';
$this->_html.= '<p>'.$this->l('This module allow to make a customers xls file.').'</p>';
$delimiter = "\t";
$toExport = array(
array('c.id_customer','"[quickid]"'),
array('c.firstname','"[name]"'),
array('c.lastname','"[lastname]"'),
array('c.siret','"[hej]"'),
array('c.email','"[email]"'),
array('c.website','Website'),
array('c.siret','"[orgno]"'),
array('c.company','"[Company]"'),
array('a.firstname','aFirstname'),
array('a.lastname','aLastname'),
array('a.address1','"[Address1]"'),
array('a.address2','"[Address2]"'),
array('a.postcode','"[zipcode]"'),
/* array('a.phone','"[phone]"'), */
array('a.phone_mobile','"[sms]"'),
);
/*
ADDRESS FIELDS CUSTOMER FIELDS
id_address id_customer
id_country id_shop_group
id_state id_shop
id_customer id_gender
id_manufacturer id_default_group
id_supplier id_risk
id_warehouse company
alias siret
company ape
lastname firstname
firstname lastname
address1 email
address2 passwd
postcode last_passwd_gen
city birthday
other newsletter
phone ip_registration_newsletter
phone_mobile newsletter_date_add
vat_number optin
dni website
date_add outstanding_allow_amount
date_upd show_public_prices
active max_payment_days
deleted secure_key
note
active
is_guest
deleted
date_add
date_upd
*/
// If we clicked the export button
if (isset($_POST['exportcustomer'])) {
$sql = "SELECT ";
$end = count($toExport)-1; // count keys in array, and remove 1 to compensate for index 0
foreach($toExport as $key=>$fields) {
$sql .= $fields[0] . " AS " . $fields[1]; // Add sql
if($key != $end) { //if not last key
$sql .= ", "; // add , to sql
}
}
$file_id = file_get_contents(dirname(__FILE__).'/id.dat');
if(!$file_id) {
$file_id = 0;
}
// this sql limits the export to the customers that have address
$sql .= " FROM "._DB_PREFIX_."customer c, "._DB_PREFIX_."address a
WHERE c.id_customer = a.id_customer && c.id_customer > $file_id
ORDER BY a.id_customer ASC";
// id_customer must be higher then file_id. So if file is 6, customer that is exported will be 7
$orderlist = Db::getInstance()->ExecuteS($sql);
// Create the xls file
$file = fopen(dirname(__FILE__).'/export_customers.xls', 'w');
$firstline = "";
foreach($toExport as $key=>$fields) {
$firstline .= $fields[1];
if($key != $end) { //if not last key
$firstline .= $delimiter;
}
}
fwrite($file, $firstline."\r\n");
foreach($orderlist AS $orderline){
fwrite($file, implode($delimiter, $orderline)."\r\n");
}
fclose($file);
// Get the id of the latest customer
$sql = "SELECT MAX(id_customer) FROM "._DB_PREFIX_."customer";
$maxid = Db::getInstance()->ExecuteS($sql);
$file = fopen(dirname(__FILE__).'/id.dat', 'w');
fwrite($file,$maxid[0]['MAX(id_customer)']);
fclose($file);
$this->_html.= 'Export completed<br>';
$this->_html .= "Next export will start at customer nr: " . ($maxid[0]['MAX(id_customer)']+1) . "<br><br>";
$this->_html.= '<a href="http://' . $_SERVER['HTTP_HOST'] . '/modules/exportcustomers/export_customers.xls" target="_blank">Download export_customers.xls</a><br>';
return $this->_html;
}
else
{
$this->_html .= '<form method="post"><input type="submit" name="exportcustomer" value="'.$this->l('Export file').'" /></form>';
$file_id = file_get_contents(dirname(__FILE__).'/id.dat');
if(!$file_id) {
$file_id = 0;
}
$this-> _html .= "<br>This export will start with customer number: " . ($file_id+1) . "<br><br>";
$this->_html .='
<h3 style="margin-top:2em;">'.$this->l('Explanation extraction :').'</h3>
<dl>
<dt><i class="champ">'.$this->l('Custno').'</i> :</dt><dd style="padding: 0.2em 0 0.6em 2em;">'.$this->l('Identification customers').'</dd>
<dt><i class="champ">'.$this->l('Gender;').'</i> :</dt><dd style="padding: 0.2em 0 0.6em 2em;">'.$this->l('(1/2) 1 is a man; 2 is a woman and 9 not known;').'</dd>
</dl>
';
$this->_html .= '<hr>';
return $this->_html;
}
}
}
?>