bebeboutik/modules/privatesales_newsletter/AdminPrivateSalesNewsletter.php

248 lines
9.9 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
include_once(_PS_ROOT_DIR_.'/modules/privatesales_extrafields/privatesales_extrafields.php');
2016-01-04 12:49:26 +01:00
class AdminPrivateSalesNewsletter extends AdminTab {
public function __construct() {
$this->lang = TRUE;
parent::__construct();
}
public function displayForm($isMainTab=TRUE) {
global $currentIndex, $cookie;
parent::displayForm();
echo '<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter').'" method="post" enctype="multipart/form-data">
<fieldset>
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Titre du dimanche').'</legend>';
echo '<label>'.$this->l('Titre du soir:').'</label>
<div class="margin-form">
<div id="title" style="float: left;">
<div style="margin-bottom:10px;">
FR : <input type="text" style="width: 500px;" name="title" value="'. Configuration::get('TITLE_NEWS_DIMANCHE') .'" />
</div>
<div style="margin:10px 0;">
ES : <input type="text" style="width: 500px;" name="title_es" value="'. Configuration::get('TITLE_NEWS_DIMANCHE_ES') .'" />
</div>
</div> <br class="clear" />';
echo '<div class="clear"></div>
</div>';
echo '
<div class="margin-form">
<input type="submit" class="button" name="submitTitleDimanche" value="'.$this->l('Update this title').'" />
</div>';
echo '</fieldset>
</form>
<br class="clear" />';
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_newsletter/privatesale.js"></script>
<script type="text/javascript">
i18n_delete = "'.$this->l('Are you sure you want to delete this newsletter?').'";
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter').'";
</script>
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter').'" method="post" enctype="multipart/form-data">
<fieldset>
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Edit a newsletter').'</legend>';
echo '<label>'.$this->l('Title:').'</label>
<div class="margin-form">
<div id="title" style="float: left;">
<input type="text" style="width: 500px;" name="title" value="'.($this->curnewsletter !== NULL? $this->curnewsletter['title']: '').'" />
</div>
<div class="clear"></div>
</div>';
echo '<label>'.$this->l('Date:').'</label>
<div class="margin-form">
<div id="date_pub" style="float: left;">
<input type="text" style="width: 70px;" name="date_pub" value="'.($this->curnewsletter !== NULL? $this->curnewsletter['date_pub']: '').'" />
<p>'.$this->l('Format: yyyy-mm-dd').'</p>
</div>
<div class="clear"></div>
</div>';
echo '<label>'.$this->l('Version:').'</label>
<div class="margin-form">
<div id="version" style="float: left;">
<select id="version" name="version">
<option '.($this->curnewsletter !== NULL ? ($this->curnewsletter['version'] == 'fr' ? 'selected' : '' ) : 'selected').' value="fr">FR</option>
<option '.($this->curnewsletter !== NULL ? ($this->curnewsletter['version'] == 'es' ? 'selected' : '' ) : '').' value="es">ES</option>
</select>
</div>
<div class="clear"></div>
</div>';
echo '<br class="clear" />
<div class="margin-form">
<input type="hidden" name="id_newsletter" value="'.($this->curnewsletter !== NULL? $this->curnewsletter['id_newsletter']: '').'" />
<input type="submit" class="button" name="submitNewsletterAdd" value="'.$this->l('Add this newsletter').'" />
<input type="submit" class="button'.($this->curnewsletter !== NULL? '': ' disable"').'" name="submitNewsletterUpdate" value="'.$this->l('Edit this newsletter').'"'.($this->curnewsletter !== NULL? '': ' disabled="disabled"').' id="submitNewsletterUpdate" />
</div>';
echo '</fieldset>
</form>';
}
public function display() {
global $cookie, $currentIndex;
$this->curnewsletter = null;
if($id = Tools::getValue('id')) {
$newsletter = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_newsletter` WHERE `id_newsletter` = '.(int) $id);
if(count($newsletter) > 0) {
$this->curnewsletter = $newsletter[0];
} else {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
}
}
$this->displayForm();
echo '<fieldset class="space">
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales_newsletter/prefs.gif" alt="" title="" /> '.$this->l('Vente en avant').'</legend>
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter').'" method="post">
<table class="table" style="width: 100%;">';
$sales = Sale::getSales(NULL, NULL, NULL, 'not_ended', FALSE, FALSE, '`position` DESC');
$ids = array();
foreach ($sales as $key => $sale) {
$ids[] = $sale->id;
}
$extrafields = PrivateSales_ExtraFields::getFieldsForSale($ids);
2016-01-04 12:49:26 +01:00
foreach($sales as $sale) {
echo '<tr '. ($sale->forward_news == 1 ? 'style="background:#f1f1f1"' : ''). '>
<td>
<label for="forward_'. $sale->id .'">'. $sale->title[2] .'<br/><span style="color:#666; font-style:italic">'.$extrafields[$sale->id][1].'</span></label>
</td>
<td>
<label for="forward_'. $sale->id .'">'. $sale->date_end .'</label>
2016-01-04 12:49:26 +01:00
</td>
<td>
<input type="checkbox" value="'. $sale->id .'" name="sale_forward['. $sale->id .']" id="forward_'. $sale->id .'" '. ($sale->forward_news == 1 ? 'checked' : '') .'/>
</td>
</tr>';
}
echo '</table>
<br class="clear" />
<div class="margin-form">
<input type="submit" class="button" name="submitForwardSale" value="'.$this->l('Mettre en avant').'" />
</div>
</fieldset>
</form>';
echo '<fieldset class="space">
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales_newsletter/prefs.gif" alt="" title="" /> '.$this->l('Newsletters list').'</legend>
<table class="table" style="width: 100%;">
<tr>
<th>'.$this->l('ID').'</th>
<th>'.$this->l('Title').'</th>
<th>'.$this->l('Date').'</th>
<th>'.$this->l('Version').'</th>
<th style="width: 55px;">'.$this->l('Actions').'</th>
</tr>';
foreach(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_newsletter`
ORDER BY `id_newsletter` DESC
LIMIT 30
') as $news) {
echo '<tr>
<td>'.$news['id_newsletter'].'</td>
<td>'.$news['title'].'</td>
<td>'.$news['date_pub'].'</td>
<td>'.$news['version'].'</td>
<td>
<img style="cursor: pointer;" onclick="itemEdition('.$news['id_newsletter'].')" title="'.$this->l('Edit this newsletter').'" alt="" src="../img/admin/edit.gif">
<img style="cursor: pointer;" onclick="itemDeletion('.$news['id_newsletter'].')" title="'.$this->l('Delete this newsletter').'" alt="" src="../img/admin/delete.gif">
</td>
</tr>';
}
echo '</table>
</fieldset>';
}
function postProcess() {
global $cookie, $currentIndex;
if(Tools::isSubmit('submitNewsletterAdd')) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_newsletter` VALUES (
DEFAULT,
"'.pSQL(Tools::getValue('title')).'",
"'.pSQL(Tools::getValue('image_url')).'",
"'.pSQL(Tools::getValue('date_pub')).'",
"'.pSQL(Tools::getValue('version')).'"
)
');
$id_newsletter = Db::getInstance()->Insert_ID();
// if(isset($_FILES['image']) && $_FILES['image']['name'] != '') {
// if(!copy($_FILES['image']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/newsletter/'.$id_newsletter.'.jpg')) {
// echo $this->displayError($this->l('An error occured during the image upload.'));
// }
// }
} elseif(Tools::isSubmit('submitNewsletterUpdate') && $id_newsletter = (int) Tools::getValue('id_newsletter')) {
if(count(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_newsletter`
WHERE `id_newsletter` = '.$id_newsletter)
) > 0) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale_newsletter`
SET `title` = "'.pSQL(Tools::getValue('title')).'",
`image_url` = "'.pSQL(Tools::getValue('image_url')).'",
`date_pub` = "'.pSQL(Tools::getValue('date_pub')).'",
`version` = "'.pSQL(Tools::getValue('version')).'"
WHERE `id_newsletter` = '.$id_newsletter.'
');
}
// if(isset($_FILES['image']) && $_FILES['image']['name'] != '') {
// if(!copy($_FILES['image']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/newsletter/'.$id_newsletter.'.jpg')) {
// echo $this->displayError($this->l('An error occured during the image upload.'));
// }
// }
} elseif(isset($_GET['delete']) && $id_newsletter = Tools::getValue('id')) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_newsletter`
WHERE `id_newsletter` = '.(int) $id_newsletter.'
');
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
} else if(Tools::isSubmit('submitTitleDimanche')) {
Configuration::updateValue('TITLE_NEWS_DIMANCHE', Tools::getValue('title'));
Configuration::updateValue('TITLE_NEWS_DIMANCHE_ES', Tools::getValue('title_es'));
Configuration::updateValue('TITLE_NEWS_LAST_DAY', Tools::getValue('title_last_day'));
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
} else if(Tools::isSubmit('submitForwardSale')) {
$forward = Tools::getValue('sale_forward', 0);
$sales = Sale::getSales(NULL, NULL, NULL, 'not_ended', FALSE, FALSE, '`position` DESC');
foreach($sales as $sale) {
if(in_array($sale->id, $forward)) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale` SET
`forward_news` = 1,
`date_upd` = NOW()
WHERE `id_sale` = '.(int) $sale->id.'
');
} else {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale` SET
`forward_news` = 0,
`date_upd` = NOW()
WHERE `id_sale` = '.(int) $sale->id.'
');
}
}
}
}
}