172 lines
4.6 KiB
PHP
Executable File
172 lines
4.6 KiB
PHP
Executable File
<?php
|
|
/*
|
|
* 2007-2014 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
*
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
* @copyright 2007-2014 PrestaShop SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class NewsletterProGroup extends Module
|
|
{
|
|
private $post_errors = array();
|
|
private $html = '';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'newsletterprogroup';
|
|
$this->tab = 'administration';
|
|
$this->version = '1.0.0';
|
|
$this->author = 'ANTADIS';
|
|
$this->need_instance = 0;
|
|
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Newsletter pro group');
|
|
$this->description = $this->l('Generates a .CSV file of pro group users');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
return parent::install();
|
|
}
|
|
|
|
private function postProcess()
|
|
{
|
|
$result = false;
|
|
if (Tools::isSubmit('submitExport'))
|
|
{
|
|
if ($res = $this->processExport()){
|
|
// download csv file
|
|
// $filename = '/export.csv';
|
|
// if (!file_exists(dirname(__FILE__).$filename))
|
|
// return false;
|
|
// chmod(dirname(__FILE__).$filename, 0755);
|
|
// header('location:'.$this->_path.$filename);
|
|
// exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function processExport()
|
|
{
|
|
$objects = $this->getCustomers();
|
|
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Content-Description: File Transfer');
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename=export_grouppro.csv;');
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
$row_definition = array(
|
|
'ID' => 'id_customer',
|
|
'Prenom' => 'firstname',
|
|
'Nom' => 'lastname',
|
|
'Email' => 'email',
|
|
'Maj_mdp' => 'pro_update',
|
|
'Deniere_maj' => 'date_upd'
|
|
);
|
|
|
|
ob_clean();
|
|
//open file pointer to standard output
|
|
$fp = fopen('php://output', 'w');
|
|
// $fp = fopen(dirname(__FILE__).'/export.csv', 'w');
|
|
$delim = ';';
|
|
|
|
// first row
|
|
$data=array();
|
|
// foreach ($row_definition as $col_name => $index)
|
|
// $data[]=Tools::htmlentitiesDecodeUTF8($col_name);
|
|
// fputcsv ($fp,$data,$delim);
|
|
|
|
foreach ($objects as $obj) {
|
|
// build CSV file
|
|
$data = array();
|
|
foreach ($row_definition as $index){
|
|
$data[] = $obj[$index];
|
|
}
|
|
|
|
fputcsv ($fp,$data,$delim);
|
|
}
|
|
fclose($fp);
|
|
exit;
|
|
// return true;
|
|
}
|
|
|
|
private function getCustomers()
|
|
{
|
|
$sql = 'SELECT *
|
|
FROM '._DB_PREFIX_.'customer
|
|
WHERE `pro` = 1
|
|
AND `pro_update` = 1';
|
|
return Db::getInstance()->executeS($sql);
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$this->html .= '';
|
|
|
|
if (!empty($_POST))
|
|
$this->postProcess();
|
|
$this->html .= $this->renderForm();
|
|
|
|
return $this->html;
|
|
}
|
|
|
|
public function renderForm()
|
|
{
|
|
$fields_form = array(
|
|
'form' => array(
|
|
'legend' => array(
|
|
'title' => $this->l('CSV export'),
|
|
'icon' => 'icon-wheel'
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Export'),
|
|
)
|
|
),
|
|
);
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->table = $this->table;
|
|
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
|
$helper->default_form_language = $lang->id;
|
|
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
|
$this->fields_form = array();
|
|
$helper->identifier = $this->identifier;
|
|
$helper->submit_action = 'submitExport';
|
|
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->tpl_vars = array(
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id
|
|
);
|
|
|
|
return $helper->generateForm(array($fields_form));
|
|
}
|
|
}
|