bebeboutik/modules/privatesales/AdminPrivateSalesSales.php

1309 lines
60 KiB
PHP
Executable File

<?php
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
require_once(_PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php');
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
class AdminPrivateSalesSales extends AdminTab {
private $imagelist;
public function __construct() {
$this->lang = TRUE;
parent::__construct();
$this->imagelist = array(
'liston' => array($this->l('Listing image (on)'), '380x178'),
'listoff' => array($this->l('Listing image (off)'), '380x178'),
'salebg' => array($this->l('Sale background'), '*x*'),
//'thumb' => array($this->l('Thumbnail'), '260x108'),
//'fb' => array($this->l('Facebook image'), '100x100'),
//'trailerbg' => array($this->l('Trailer background'), '*x*'),
//'trailercenter' => array($this->l('Trailer center background'), '560x*'),
);
}
public function displayForm($isMainTab=TRUE) {
global $currentIndex, $cookie;
parent::displayForm();
$iso = Language::getIsoById((int)($cookie->id_lang));
$images = array();
foreach(array_keys($this->imagelist) as $img) {
$images[] = 'img_'.$img;
}
$divLangName = 'description¤video¤'.implode('¤', $images).'¤img_banner_mobile¤m_extrafields_1_value¤m_extrafields_2_value';
$divLangImgName = 'description¤video¤'.implode('¤', $images).'¤img_banner_mobile¤m_extrafields_1_value¤m_extrafields_2_value';
$helperForm = new HelperFormBootstrap();
$helperForm->_select2 = true;
$helperForm->_inputMask = true;
$helperForm->_inputSwitch = true;
$helperForm->_js .='<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales/privatesale.js"></script>
<script type="text/javascript">
i18n_delete = "'.$this->l('Are you sure you want to delete this sale?').'";
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales').'";
</script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales/jquery.multiSelect.js"></script>';
$helperForm->_css .='<style type="text/css">
option[disabled] {
background: #efefef;
}
.ui-sortable-handle{
cursor:move;
}
a.multiSelect {
background: #FFF url('.__PS_BASE_URI__.'modules/privatesales/dropdown.blue.png) right -1px no-repeat;
border: 1px solid #e0d0b1;
padding-right: 20px;
position: relative;
cursor: default;
text-decoration: none;
color: black;
display: -moz-inline-stack;
display: inline-block;
vertical-align: top;
margin-top: 2px;
}
a.multiSelect:link, a.multiSelect:visited, a.multiSelect:hover, a.multiSelect:active {
color: black;
text-decoration: none;
}
a.multiSelect span {
margin: 1px 0px 1px 3px;
overflow: hidden;
display: -moz-inline-stack;
display: inline-block;
white-space: nowrap;
font-size: 12px;
}
a.multiSelect.hover {
background-image: url('.__PS_BASE_URI__.'modules/privatesales/dropdown.blue.hover.png);
}
a.multiSelect.active, a.multiSelect.focus {
border: inset 1px #000000;
}
a.multiSelect.active {
background-image: url('.__PS_BASE_URI__.'modules/privatesales/dropdown.blue.active.png);
}
.multiSelectOptions {
margin-top: -1px;
overflow-y: auto;
overflow-x: hidden;
border: solid 1px #b2b2b2;
background: #ffffff;
}
.multiSelectOptions label {
padding: 0px 2px;
display: block;
white-space: nowrap;
float: none;
text-align: left;
width: auto;
}
.multiSelectOptions label.optGroup {
font-weight: bold;
}
.multiSelectOptions .optGroupContainer label {
padding-left: 10px;
font-size: 12px;
color: #333333;
padding: 2px 0px;
}
.multiSelectOptions.optGroupHasCheckboxes .optGroupContainer label {
padding-left: 18px;
}
.multiSelectOptions input {
vertical-align: middle;
margin-right: 5px;
}
.multiSelectOptions label.checked {
background-color: #dce5f8;
}
.multiSelectOptions label.optGroup {
color: #000000;
font-size: 12px;
margin-bottom: 2px;
}
.multiSelectOptions label.selectAll {
border-bottom: dotted 1px #cccccc;
font-size: 12px;
color: #333333;
padding-top: 2px;
margin: 0px 0px 6px;
}
.multiSelectOptions label.hover {
background-color: #3399ff;
color: #ffffff;
}
.green {
background : #C0E3B5;
color: #55b239!important;
font-weight:bold;
}
.red {
background : #f29b9b;
}
.rose {
background : rgba(226,110,162,0.2);
color: #e36ea2!important;
}
.table tr:nth-child(even) {
background: #F1F1F1;
}
.table>tbody>tr>td{
color:#504d8b;
vertical-align:middle;
font-size:0.9em;
padding: 0 6px 0 4px;
}
.table .input-group-btn .btn{
padding: 4px 5px;
color: #504d8b;
}
</style>';
echo $helperForm->renderStyle();
echo '<div class="panel">
<div class="panel-title">
<h2>'.$this->l('Edit a sale').'</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<form class="form-horizontal" id="sale_form" action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales').'" method="post" enctype="multipart/form-data">';
$categories = Db::getInstance()->ExecuteS('
SELECT c.`id_category`, l.`name`, l.`link_rewrite`
FROM `'._DB_PREFIX_.'category` c, `'._DB_PREFIX_.'category_lang` l
WHERE c.`id_category` = l.`id_category`
AND l.`id_lang` = '.intval($cookie->id_lang).'
AND c.`id_parent` = '.Configuration::get('PRIVATESALES_ROOT').'
ORDER BY c.`id_category`
');
$used_categories = array();
foreach(Db::getInstance()->ExecuteS('
SELECT p.`id_category`
FROM `'._DB_PREFIX_.'privatesale_category` p
WHERE `id_category` IN (
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category` c
WHERE c.`id_parent` = '.Configuration::get('PRIVATESALES_ROOT').'
)
') as $cat) {
$used_categories[] = $cat['id_category'];
}
$categories_ordered = array();
foreach($categories as $category) {
$categories_ordered[(string) $category['id_category']] = $category;
$id_category_options[(int)$category['id_category']] = array(
'label' => $category['id_category'].' - '.$category['name'],
'value' => (int) $category['id_category']
);
if($this->cursale!==NULL && $this->cursale->id_category==$category['id_category']) {
$id_category_options[(int)$category['id_category']]['selected'] = true;
}elseif(in_array($category['id_category'], $used_categories)){
$id_category_options[(int)$category['id_category']]['disabled'] = true;
}
}
$helperForm->_js .= '<script type="text/javascript">
var categories_ordered = {};
categories_ordered = '.json_encode($categories_ordered).';
$(document).ready(function() {
if($("#id_category").val() != null && $("#id_category").val() != \'undefined\') {
$("#title").attr("value", categories_ordered[$("#id_category").val()].name);
$("#alias").attr("value", categories_ordered[$("#id_category").val()].link_rewrite);
}
$("#id_category").change(function(){
$("#title").attr("value", categories_ordered[$("#id_category").val()].name);
$("#alias").attr("value", categories_ordered[$("#id_category").val()].link_rewrite);
});
$("#date_start").inputmask("9999-99-99 99:99:99");
$("#date_end").inputmask("9999-99-99 99:99:99");
});
</script>';
echo '<div class="col-md-5">';
// select root category
$input = array(
'type' => 'select2',
'label' => $this->l('Root category'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'id_category',
'options' => $id_category_options,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// title
$input = array(
'type' => 'text',
'label' => $this->l('Title'),
// 'label-class' => 'col-md-2',
// 'input-class' => 'col-md-8',
'disabled' => true,
'name' => 'title',
'help' => $this->l('This value is set by the name of the root category for this sale.'),
'default' => ($this->cursale!==NULL? $categories_ordered[$this->cursale->id_category]['name']: (in_array($categories[0]['id_category'], $used_categories)? '': $categories[0]['name'])),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Alias
$input = array(
'type' => 'text',
'label' => $this->l('Alias'),
// 'label-class' => 'col-md-2',
// 'input-class' => 'col-md-8',
'disabled' => true,
'name' => 'alias',
'help' => $this->l('This value is set by the alias of the root category for this sale.'),
'default' => ($this->cursale!==NULL? $categories_ordered[$this->cursale->id_category]['link_rewrite']: (in_array($categories[0]['id_category'], $used_categories)? '': $categories[0]['link_rewrite'])),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Date start
$input = array(
'type' => 'simpleDate',
'id' => 'date_start',
'name' => 'date_start',
'label' => $this->l('Start date'),
// 'label-class' => 'control-label col-md-2',
// 'input-class' => 'col-md-7',
'after' => '<span class="glyphicon glyphicon-calendar"></span>',
'value' => ($this->cursale!==NULL? $this->cursale->date_start: ''),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Date end
$input = array(
'type' => 'simpleDate',
'id' => 'date_end',
'name' => 'date_end',
'label' => $this->l('End date'),
// 'label-class' => 'control-label col-md-2',
// 'input-class' => 'col-md-7',
'after' => '<span class="glyphicon glyphicon-calendar"></span>',
'value' => ($this->cursale!==NULL? $this->cursale->date_end: ''),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
echo '</div><div class="col-md-5 col-md-offset-2" style="background:#eee;padding:10px;border-radius:7px;">';
// Status
$input = array(
'type' => 'switch',
'name' => 'enabled',
'label' => $this->l('Active :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->enabled==0?0:1):1),
'checked' => ($this->cursale!==NULL?($this->cursale->enabled==0?0:1):1),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Display
$input = array(
'type' => 'switch',
'name' => 'logout',
'label' => $this->l('Affichage non inscrits :'),
// 'label_on' => '<span class="anticon anticon-user-check text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-user-minus text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->logout==0?0:1):1),
'checked' => ($this->cursale!==NULL?($this->cursale->logout==0?0:1):1),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Public
$input = array(
'type' => 'switch',
'name' => 'pub',
'label' => $this->l('Public sale:'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->pub==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->pub==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Braderie
$input = array(
'type' => 'switch',
'name' => 'braderie',
'label' => $this->l('Braderie :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->braderie==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->braderie==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Featured
$input = array(
'type' => 'switch',
'name' => 'featured',
'label' => $this->l('Featured sale:'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->featured==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->featured==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// New
$input = array(
'type' => 'switch',
'name' => 'new',
'label' => $this->l('Nouveau :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->new==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->new==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Newsletter
$input = array(
'type' => 'switch',
'name' => 'forward_news',
'label' => $this->l('Mise en avant Newsletter :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->forward_news==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->forward_news==0?0:1):0),
'required' => true,
);
//echo $helperForm->generateInput($input);
//echo '<div class="clearfix"></div>';
// Shipping only fr
$input = array(
'type' => 'switch',
'name' => 'shipping_fr',
'label' => $this->l('Livraison seulement en France :'),
// 'label_on' => '<span class="anticon anticon-checkmark text-green-light"></span>',
// 'label_off' => '<span class="anticon anticon-cross text-rose"></span>',
'label-class' => 'col-sm-8',
'input-class' => 'col-sm-4',
'default' => ($this->cursale!==NULL?($this->cursale->shipping_fr==0?0:1):0),
'checked' => ($this->cursale!==NULL?($this->cursale->shipping_fr==0?0:1):0),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="col-sm-5">';
$id_employee_options = array();
foreach(Employee::getEmployeesByProfile(array(1,5)) as $e) {
$id_employee_options[(int)$e['id_employee']] = array(
'label' => $e['name'],
'value' => (int) $e['id_employee']
);
if($this->cursale!==NULL && $this->cursale->id_employee==$e['id_employee']){
$id_employee_options[(int)$e['id_employee']]['selected'] = true;
}
}
// Employee manager
$input = array(
'type' => 'select2',
'label' => $this->l('Sale manager:'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'id_employee',
'options' => $id_employee_options,
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
$id_delay_options = array(
array(
'label' => $this->l('Livraison classique'),
'value' => 1,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 1?true:false)
),
array(
'label' => $this->l('Livraison 48h'),
'value' => 2,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 2?true:false)
),
array(
'label' => $this->l('Livraison 7 Jours'),
'value' => 3,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 3?true:false)
),
array(
'label' => $this->l('Livraison 10 Jours'),
'value' => 4,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 4?true:false)
),
array(
'label' => $this->l('Livraison Noel'),
'value' => 5,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 5?true:false)
),
array(
'label' => $this->l('Produit Star'),
'value' => 6,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 6?true:false)
),
array(
'label' => $this->l('Livraison 72h'),
'value' => 7,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 7?true:false)
),
array(
'label' => $this->l('Livraison 48h Noel'),
'value' => 8,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 8?true:false)
),
array(
'label' => $this->l('Livraison spécifique'),
'value' => 9,
'selected' => ($this->cursale!==NULL && $this->cursale->delivery_delay== 8?true:false)
),
);
// Delivery delay
$input = array(
'type' => 'select2',
'label' => $this->l('Délai de livraison :'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'delivery_delay',
'options' => $id_delay_options,
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
$id_group_options = array();
foreach(Db::getInstance()->ExecuteS('
SELECT l.`id_group`, l.`name`'.($this->cursale !== NULL? ', (
SELECT IFNULL(g.`id_sale`, NULL) FROM `'._DB_PREFIX_.'privatesale_group` g WHERE l.`id_group` = g.`id_group` AND g.`id_sale` = '.$this->cursale->id.'
) AS `id_sale`': '').'
FROM `'._DB_PREFIX_.'group_lang` l
WHERE l.`id_lang` = '.$cookie->id_lang
) as $group) {
$id_group_options[(int)$group['id_group']] = array(
'label' => $group['name'],
'value' => (int) $group['id_group']
);
if(isset($group['id_sale']) && $group['id_sale'] !== NULL){
$id_group_options[(int)$group['id_group']]['selected'] = true;
}
if(!isset($this->cursale->id) && $group['id_group'] == 1){
$id_group_options[(int)$group['id_group']]['selected'] = true;
}
}
// Group
$input = array(
'type' => 'select2',
'label' => $this->l('Groups:'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'm_groups[]',
'id' => 'm_groups',
'option_all' => true,
'option_clear' => true,
'options' => $id_group_options,
'multiple' => true,
'placeholder' => $this->l('Select one or more groups...'),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
$id_version_options = array(
array(
'label'=> 'fr',
'value'=>'fr',
'selected'=>false,
),
array(
'label'=>'es',
'value'=>'es',
'selected'=>false,
),
);
foreach($id_version_options as &$version) {
if(isset($this->cursale->id) && in_array($version['value'], $this->cursale->versions)){
$version['selected'] = true;
}
if(!isset($this->cursale->id) && $version['value'] == 'fr') {
$version['selected'] = true;
}
}
// Version
$input = array(
'type' => 'select2',
'label' => $this->l('Versions :'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'm_versions[]',
'id' => 'm_versions',
'option_all' => true,
'option_clear' => true,
'options' => $id_version_options,
'multiple' => true,
'placeholder' => $this->l('Select one or more versions...'),
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
$id_country_options = array();
$id_country_options[0] = array(
'label' => 'Choisir...',
'value' => (int) 0
);
foreach (Country::getCountries($cookie->id_lang, false) as $country) {
$id_country_options[(int)$country['id_country']] = array(
'label' => $country['name'],
'value' => (int) $country['id_country']
);
if($this->cursale!==NULL && $this->cursale->id_country==$country['id_country']){
$id_country_options[(int)$country['id_country']]['selected'] = true;
}
}
// country
$input = array(
'type' => 'select2',
'label' => $this->l('Pays de la Vente :'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'id_country',
'options' => $id_country_options,
'required' => true,
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// if(Configuration::get('PRIVATESALES_CARRIERFENCE')) {
$carriers = Db::getInstance()->ExecuteS('
SELECT c.`id_carrier`, IF(c.`name` = "0", "'.Configuration::get('PS_SHOP_NAME').'", c.`name`) AS `name`'.($this->cursale !== NULL? ', (
SELECT IFNULL(p.`id_sale`, NULL) FROM `'._DB_PREFIX_.'privatesale_carrier` p WHERE c.`id_carrier` = p.`id_carrier` AND p.`id_sale` = '.$this->cursale->id.'
) AS `id_sale`': '').'
FROM `'._DB_PREFIX_.'carrier` c
WHERE c.`deleted` != 1 AND c.active =1
');
$carriers_default = Configuration::get('ANT_CARRIERS_SOCOL').','.Configuration::get('ANT_CARRIERS_MR');
$carriers_default = explode(',',Configuration::get('ANT_CARRIERS_SOCOL').','.Configuration::get('ANT_CARRIERS_MR'));
$carriers_dom = explode(',',Configuration::get('ANT_CARRIER_DOM'));
$carriers_drop = explode(',',Configuration::get('ANT_CARRIER_DROP'));
$id_carrier_options = array();
foreach ($carriers as $carrier) {
$id_carrier_options[$carrier['id_carrier']] = array(
'label' => $carrier['name'],
'value' => $carrier['id_carrier']
);
if(Tools::getIsset('edit') && (isset($carrier['id_sale']) && $carrier['id_sale'] !== NULL)) {
$id_carrier_options[$carrier['id_carrier']]['selected'] = true;
} elseif (!Tools::getIsset('edit') && in_array($carrier['id_carrier'], $carriers_default)) {
$id_carrier_options[$carrier['id_carrier']]['selected'] = true;
}
}
// Carriers
$input = array(
'type' => 'select2',
'label' => $this->l('Carriers :'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'm_carriers[]',
'id' => 'm_carriers',
'option_all' => true,
'option_clear' => true,
'options' => $id_carrier_options,
'multiple' => true,
'placeholder' => $this->l('Select one or more carriers...'),
'required' => true,
'buttons' => array(
array(
'label' => 'Classic',
'value' => '"'.implode('","',$carriers_default).'"',
'class' => 'defaut_for_',
),
array(
'label' => 'Dom',
'value' => '"'.implode('","',$carriers_dom).'"',
'class' => 'dom_for_',
),
array(
'label' => 'Dropshipping',
'value' => '"'.implode('","',$carriers_drop).'"',
'class' => 'drop_for_',
),
),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Description
$input = array(
'type' => 'textarea',
'label' => $this->l('Description:'),
'lang' => true,
'name' => 'description',
'id' => 'description',
'required' => true,
'languages' => $this->_languages,
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'default' => ($this->cursale !== NULL?$this->cursale->description:'')
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// Video
$input = array(
'type' => 'text',
'label' => $this->l('Video:'),
'lang' => true,
'name' => 'video',
'id' => 'video',
'required' => true,
'languages' => $this->_languages,
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'default' => ($this->cursale !== NULL?$this->cursale->video:'')
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
Module::hookExec('privatesales_edit', array('sale' => $this->cursale));
echo '</div>
<div class="col-sm-5 col-sm-offset-2" style="background:#eee;padding:20px; border-radius:7px;">
<h4 class="text-center"><span class="anticon anticon-images"></span> Images</h4>';
foreach($this->imagelist as $k => $v) {
$input = array(
'type' => 'uploadImage',
'lang' => true,
'label' => $v[0],
'name' => 'img_'.$k,
'name_img' => $k,
'id' => $k,
'help' => $this->l('Size:').' '.$v[1],
'languages' => $this->_languages,
'default_language' => 2,
'input-class' => '',
'id_langs' => $divLangImgName,
'link_flag_img' => '../img/l/',
'url_imgs' => ($this->cursale !== NULL?__PS_BASE_URI__.'modules/privatesales/img/'.$this->cursale->id.'/':''),
'url_to_check' => ($this->cursale !== NULL?_PS_ROOT_DIR_.'/modules/privatesales/img/'.$this->cursale->id.'/':''),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
}
$input = array(
'type' => 'uploadImage',
'lang' => true,
'label' => 'Bannière Promo (Mobile)',
'name' => 'img_banner_mobile',
'name_img' => 'banner_mobile',
'id' => 'banner_mobile',
'help' => $this->l('Size:').' 500*178',
'languages' => $this->_languages,
'default_language' => 2,
'input-class' => '',
'id_langs' => $divLangImgName,
'link_flag_img' => '../img/l/',
'img_delete' => ($this->cursale !== NULL?$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales').'&delete_img=banner_mobile&id='.$this->cursale->id:''),
'url_imgs' => ($this->cursale !== NULL?__PS_BASE_URI__.'modules/privatesales/img/'.$this->cursale->id.'/':''),
'url_to_check' => ($this->cursale !== NULL?_PS_ROOT_DIR_.'/modules/privatesales/img/'.$this->cursale->id.'/':''),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
echo '</div>
<div class="clear"></div>
<div class="ln_solid-small"></div>
<div class="text-center">
<input type="hidden" name="id_sale" value="'.($this->cursale !== NULL? $this->cursale->id: '').'" />
<input type="submit" class="btn btn-primary" '.($this->cursale !== NULL ? 'disabled=disabled': '').' name="submitSaleAdd" value="'.$this->l('Add this sale').'" />
<input type="submit" class="btn btn-primary'.($this->cursale !== NULL? '': ' disable"').'" name="submitSaleUpdate" value="'.$this->l('Edit this sale').'"'.($this->cursale !== NULL? '': ' disabled="disabled"').' id="submitSaleUpdate" />
</div>';
echo '</form>
</div>
</div>';
echo $helperForm->renderScript();
}
public function display() {
global $cookie, $currentIndex;
$this->cursale = NULL;
if($id = Tools::getValue('id')) {
$this->cursale = new Sale($id);
if($this->cursale->id === NULL) {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
}
if(Tools::getValue('delete_img') && $id_lang = Tools::getValue('id_lang')) {
unlink(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$this->cursale->id.'/'.Tools::getValue('delete_img').'_'.$id_lang.'.jpg');
}
}
// // ANTADIS INSERT TYPE
// $ventes = Sale::getSales(NULL, NULL, NULL, NULL , FALSE, FALSE, 'position ASC');
// foreach ($ventes as $key => $vente) {
// global $cookie;
// if($cookie->id_employee == 1){
// Db::getInstance()->autoExecute('ps_privatesale_type', array(
// 'id_sale' => $vente->id,
// 'id_sale_type' => $vente->sale_type,
// ), 'INSERT');
// }
// }
$this->displayForm();
$export = Module::isInstalled('exports');
$employees = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`, `firstname`, `lastname`
FROM `'._DB_PREFIX_.'employee`
') as $row) {
$employees[(int) $row['id_employee']] = $row['firstname'].' '.$row['lastname'];
}
$sale_shipping = array();
foreach(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_shipping_sale`
WHERE 1
') as $ss) {
$sale_shipping[$ss['id_sale']] = $ss['id_shipping'];
}
?>
<script>
function updatePositionVP(way,position) {
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'position=' + position + '&way='+ way +'&updatePosition',
success: function() {
var type = $('.tri.active').attr('name');
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'type=' + type + '&getSales',
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
});
}
jQuery( document ).ready(function( $ ) {
var button = $('.tri');
button.click(function(){
var type = $(this).attr('name');
if(!$(this).hasClass('active')){
button.removeClass('active');
$(this).addClass('active');
$('.list_vente').empty();
var loader = "<p style='text-align:center'><img src='../img/loader_payment.gif' /></p>";
$('.list_vente').html(loader);
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'type=' + type + '&getSales',
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
});
$(".updatePosition").click(function(e) {
e.preventDefault();
var position = $(this).attr('data-position');
var way = $(this).attr('data-way');
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'position=' + position + '&way='+ way +'&updatePosition',
success: function() {
var type = $('.tri.active').attr('name');
$.ajax({
url: "ajax_vp.php",
type: 'GET',
data: 'type=' + type + '&getSales',
success: function(html) {
$('.list_vente').empty();
$('.list_vente').html(html);
sortable_active();
}
});
}
});
return false;
});
});
</script>
<?php
//echo '<script type="text/javascript" src="../js/jquery/jquery-ui.min.js"></script>';
echo '<script language="javascript" type="text/javascript">
<!--
$(function() {
ajax_query = function(){
$.ajax({
url: "ajax_vp.php",
type: "GET",
data: "type=not_ended&getSales",
success: function(html) {
$(".list_vente").empty();
$(".list_vente").html(html);
sortable_active();
$("html, body").animate({
scrollTop: $(".list_vente").offset().top
}, 200);
}
});
};
sortable_active = function(){
$("#saleActive").sortable({
axis : "y",
opacity : 0.6,
cancel: ".not-sortable",
start: function(event, ui) {
initial_position = ui.item.index();
},
stop: function(event, ui) {
final_position = ui.item.index();
diff = initial_position - final_position;
if(diff != 0){
id_sale = ui.item.attr("id");
$.ajax({
url: "ajax_vp.php",
type: "GET",
data: "id_sale=" + id_sale + "&position=" + diff +"&updatePositionDrag",
success: function(html) {
var loader = "<p style=\"text-align:center\"><img style=\"display:inline-block;\" src=\"../img/loader_payment.gif\" /></p>";
$(".list_vente").html(loader);
ajax_query();
}
});
}
},
});
};
sortable_active();
$("#saleActive").disableSelection();
});
//-->
</script>
';
echo '
<div class="panel">
<div class="panel-title">
<h2>'.$this->l('Sales list').'</h2>
<div class="nav navbar-right panel_toolbox">
<div class="btn-group">
<button type="submit" name="not_ended" class="tri btn btn-default active">Ventes actuelles</button>
<button type="submit" name="finished" class="tri btn btn-default">Ventes terminées</button>
<button type="submit" name="all" class="tri btn btn-default">Toutes les ventes</button>
<!--a style="cursor: pointer;" onclick="resortPosition();" class="btn btn-default">Resort</a-->
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<table class="table list_vente table-custombordered" style="width: 100%;">
<thead>
<tr>
<th>'.$this->l('ID').'</th>
<th>'.$this->l('Cat.').'</th>
<th>'.$this->l('Title').'</th>
<th>'.$this->l('Start').'</th>
<th>'.$this->l('End').'</th>
<th>'.$this->l('Enabled').'</th>
<th>'.$this->l('Nouveau').'</th>
<th>'.$this->l('Employee').'</th>
<th>'.$this->l('FR').'</th>
<th>'.$this->l('ES').'</th>
<th>'.$this->l('Delay').'</th>
<th>'.$this->l('Expe').'</th>
<th>'.$this->l('News').'</th>
<th>'.$this->l('Position').'</th>
<th>'.$this->l('Actions').'</th>
</tr>
</thead>';
echo ' <tbody id="saleActive" class="sortable">';
$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);
foreach($sales as $key => $sale) {
$delay = SaleDelay::getDelaySmallName($sale->delivery_delay,2);
echo '<tr id="item_'.$sale->id. '" class="sale_'.($key%2).'">
<td>'.$sale->id.'</td>
<td>'.$sale->id_category.'</td>
<td><strong>'.$sale->title[intval($cookie->id_lang)].'</strong><br/><span style="color:#666; font-style:italic; font-size:11px;">'.$extrafields[$sale->id][1].'</span></td>
<td style="font-size:11px;">'.$sale->date_start.'</td>
<td style="font-size:11px;">'.$sale->date_end.'</td>
<td align="center">'.($sale->enabled?'<span class="anticon anticon-checkmark text-green-light"></span>':'<span class="anticon anticon-cross text-rose"></span>').'</td>
';
if($sale->new == 0){
echo "<td align='center'>".$this->l('No')."</td>";
}
else if($sale->new == 1){
echo "<td align='center'>".$this->l('Yes')."</td>";
}
else if($sale->new == 3){
echo "<td align='center'>".$this->l('Non défini')."</td>";
}
echo '<td>'.((int) $sale->id_employee != 0? $employees[(int) $sale->id_employee]: '--').'</td>
<td class="text-center '.(in_array('fr', $sale->versions) ? 'green' : 'rose').'">FR</td>
<td class="text-center '.(in_array('es', $sale->versions) ? 'green' : 'rose').'">ES</td>
<td align="center">'.$delay.'</td>
<td align="center">'.(isset($sale_shipping[(int) $sale->id])? ($sale_shipping[(int) $sale->id] == 1? 'Philea': ''): '').'</td>
<td align="center">'. $sale->forward_news .'</td>
<td align="center" class="position">';
if($sale->lock_position == 1){
echo '<span class="anticon anticon-lock"></span>';
} else {
if($key != 0){
echo '<a href="" class="updatePosition" data-way="0" data-position='. $sale->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
}
if($key + 1 != count($sales)){
echo ' <a href="" class="updatePosition" data-way="1" data-position='. $sale->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
}
}
$category_link = Link::getCategoryLink($sale->id_category);
$category_link_bo = '?tab=AdminCatalog&viewcategory&id_category='.$sale->id_category.'&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee));
echo '</td>
<td>
<div class="input-group-btn" role="group">
<button class="btn btn-default" onclick="itemEdition('.$sale->id.')" title="Editer la vente">
<span style="font-size:12px;" class="anticon anticon-pencil2"></span>
</button>
<a href="'.$category_link.'" target="_blank" class="btn btn-default" title="Voir la vente sur le site">
<span style="font-size:12px;" class="anticon anticon-eye"></span>
</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span style="font-size:12px;" class="anticon anticon-menu"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
'.($export? '
<li>
<a onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'modules/exports/exports/privatesales.php?id_sale='.$sale->id.'&amp;adtoken='.Tools::encrypt('PrivateSalesDirectExtract'.$sale->id).'">
<i class="glyphicon glyphicon-new-window"></i> Exporter
</a>
</li>':'').'
<li>
<a onclick="window.open(this.href); return false;" href="'.$category_link_bo.'">
<i class="glyphicon glyphicon-eye-open"></i> Voir Catégorie BO
</a>
</li>
<li>
<a style="cursor: pointer;" onclick="'.($sale->lock_position?'itemUnLockPosition('.$sale->id.')':'itemLockPosition('.$sale->id.')').'">
<span class="anticon anticon-lock"></span> '.($sale->lock_position?'Défixer':'Fixer').' position
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a style="cursor: pointer;" onclick="itemDeletion('.$sale->id.')">
<span class="anticon anticon-bin"></span> Supprimer
</a>
</li>
</ul>
</div>
</td>
</tr>
';
// '.($export? '<a onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'modules/exports/exports/privatesales.php?id_sale='.$sale->id.'&amp;adtoken='.Tools::encrypt('PrivateSalesDirectExtract'.$sale->id).'"><img style="cursor: pointer;" title="Exporter cette vente" alt="" src="../img/admin/export.gif"></a>': '').'
// <img style="cursor: pointer;" onclick="itemEdition('.$sale->id.')" title="Éditer cette vente" alt="" src="../img/admin/edit.gif">
// <img style="cursor: pointer;" onclick="itemDeletion('.$sale->id.')" title="Supprimer cette vente" alt="" src="../img/admin/delete.gif">
// <a href="'.$category_link.'" target="_blank">
// <img style="cursor: pointer;" title="Voir cette vente" alt="" src="../img/admin/details.gif">
// </a>
}
echo '
</tbody>
</table>
</div>
</div>';
}
public static function getSaleType($sale_type){
$type = "";
if(in_array(1, $sale_type)){
$type.= "Bébé ";
}
if(in_array(2, $sale_type)){
$type.= "Enfant ";
}
if(in_array(3, $sale_type)){
$type.= "Maman ";
}
if(empty($type)){
return "undefined";
}
return $type;
}
public function postProcess() {
global $cookie, $currentIndex;
if(Tools::isSubmit('submitSaleAdd')) {
if (Sale::getSaleFromCategory(Tools::getValue('id_category'))) {
return false;
}
$sql_position = 'SELECT MAX(position) FROM '. _DB_PREFIX_.'privatesale';
$position = Db::getInstance()->getValue($sql_position);
$sale = new Sale();
$sale->date_start = Tools::getValue('date_start', '0000-00-00 00:00:00');
$sale->date_end = Tools::getValue('date_end', '0000-00-00 00:00:00');
$sale->id_country = (int) Tools::getValue('id_country');
$sale->enabled = Tools::getValue('enabled', 0);
$sale->featured = Tools::getValue('featured', 0);
$sale->logout = Tools::getValue('logout', 0);
$sale->new = Tools::getValue('new', 0);
$sale->braderie = Tools::getValue('braderie', 0);
$sale->forward_news = Tools::getValue('forward_news', 0);
$sale->pub = Tools::getValue('pub', 0);
$sale->id_category = Tools::getValue('id_category', Configuration::get('PRIVATESALES_ROOT'));
$sale->id_employee = (int) Tools::getValue('id_employee');
$sale->shipping_fr = (int) Tools::getValue('shipping_fr');
$sale->delivery_delay = (int) Tools::getValue('delivery_delay');
$sale->sale_type = array();
$sale->versions = array();
foreach(Tools::getValue('sale_type', array()) as $sale_type) {
$sale->sale_type[] = (int) $sale_type;
}
foreach(Language::getLanguages(FALSE) as $language) {
if($description = Tools::getValue('description_'.$language['id_lang'])) {
$sale->description[$language['id_lang']] = $description;
} else {
$sale->description[$language['id_lang']] = '';
}
if($video = Tools::getValue('video_'.$language['id_lang'])) {
$sale->video[$language['id_lang']] = $video;
} else {
$sale->video[$language['id_lang']] = '';
}
}
foreach(Tools::getValue('m_groups', array()) as $group) {
$sale->groups[] = (int) $group;
}
foreach(Tools::getValue('m_versions', array()) as $version) {
$sale->versions[] = pSql($version);
}
foreach(Tools::getValue('m_carriers', array()) as $carrier) {
$sale->carriers[] = (int) $carrier;
}
if( empty($sale->carriers)) {
echo '<div class="error alert">'.Tools::displayError($this->l('Impossible de créer une vente sans transporteur.')).'</div>';
exit;
}
$sale->save();
$sale->buildCategoryCache();
if( empty($sale->carriers)) {
mail('valentin@bebeboutik.com', 'Vente sans transporteur',
'La vente '. $sale->id.' est sans transporteur',
'Content-Type: text/plain; charset="utf-8"'."\r\n".'From: contact@bebeboutik.com'."\r\n".'Reply-To: thibault@antadis.com'."\r\n".'Return-Path: thibault@antadis.com'."\r\n");
}
if(!is_dir(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id)) {
mkdir(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id, 0775);
}
$images = array_keys($this->imagelist);
$images[] = 'banner_mobile';
foreach(Language::getLanguages(FALSE) as $language) {
foreach($images as $img) {
if((int)$language['id_lang'] == 3 && ($img == 'liston' || $img == 'listoff' || $img == 'thumb' || $img == 'salebg')
&& (!isset($_FILES['img_'.$img.'_'.$language['id_lang']]) || $_FILES['img_'.$img.'_'.$language['id_lang']]['name'] == '')
&& (isset($_FILES['img_'.$img.'_2']) && $_FILES['img_'.$img.'_2']['name'] != '')
) {
if(!copy($_FILES['img_'.$img.'_2']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id.'/'.$img.'_'.$language['id_lang'].'.jpg')) {
echo $this->displayError($this->l('An error occured during the image upload.'));
}
}
elseif(isset($_FILES['img_'.$img.'_'.$language['id_lang']]) && $_FILES['img_'.$img.'_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img_'.$img.'_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id.'/'.$img.'_'.$language['id_lang'].'.jpg')) {
echo $this->displayError($this->l('An error occured during the image upload.'));
}
}
}
}
} elseif(Tools::isSubmit('submitSaleUpdate') && $id_sale = (int) Tools::getValue('id_sale')) {
$sale = new Sale($id_sale);
$sale->date_start = Tools::getValue('date_start', '0000-00-00 00:00:00');
$sale->date_end = Tools::getValue('date_end', '0000-00-00 00:00:00');
$sale->id_country = (int) Tools::getValue('id_country');
$sale->enabled = Tools::getValue('enabled', 0);
$sale->featured = Tools::getValue('featured', 0);
$sale->logout = Tools::getValue('logout', 0);
$sale->pub = Tools::getValue('pub', 0);
$sale->new = Tools::getValue('new', 0);
$sale->braderie = Tools::getValue('braderie', 0);
$sale->forward_news = Tools::getValue('forward_news', 0);
$sale->id_category = Tools::getValue('id_category', Configuration::get('PRIVATESALES_ROOT'));
$sale->id_employee = (int) Tools::getValue('id_employee');
$sale->shipping_fr = (int) Tools::getValue('shipping_fr');
$sale->delivery_delay = (int) Tools::getValue('delivery_delay');
$sale->sale_type = array();
$sale->description = array();
$sale->video = array();
$sale->groups = array();
$sale->carriers = array();
$sale->versions = array();
foreach(Language::getLanguages(FALSE) as $language) {
if($description = Tools::getValue('description_'.$language['id_lang'])) {
$sale->description[$language['id_lang']] = $description;
} else {
$sale->description[$language['id_lang']] = '';
}
if($video = Tools::getValue('video_'.$language['id_lang'])) {
$sale->video[$language['id_lang']] = $video;
} else {
$sale->video[$language['id_lang']] = '';
}
}
foreach(Tools::getValue('m_groups', array()) as $group) {
$sale->groups[] = (int) $group;
}
foreach(Tools::getValue('m_carriers', array()) as $carrier) {
$sale->carriers[] = (int) $carrier;
}
foreach(Tools::getValue('m_versions', array()) as $version) {
$sale->versions[] = pSql($version);
}
foreach(Tools::getValue('sale_type', array()) as $sale_type) {
$sale->sale_type[] = (int) $sale_type;
}
if( empty($sale->carriers)) {
echo '<div class="error alert">'.Tools::displayError($this->l('Impossible d\'éditer une vente sans transporteur.')).'</div>';
exit;
}
$sale->save();
$sale->buildCategoryCache();
if(!is_dir(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id)) {
mkdir(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id, 0775);
}
$images = array_keys($this->imagelist);
$images[] = 'banner_mobile';
foreach(Language::getLanguages(FALSE) as $language) {
foreach($images as $img) {
if((int)$language['id_lang'] == 3 && ($img == 'liston' || $img == 'listoff' || $img == 'thumb' || $img == 'salebg')
&& (!isset($_FILES['img_'.$img.'_'.$language['id_lang']]) || $_FILES['img_'.$img.'_'.$language['id_lang']]['name'] == '')
&& (isset($_FILES['img_'.$img.'_2']) && $_FILES['img_'.$img.'_2']['name'] != '')
) {
if(!copy($_FILES['img_'.$img.'_2']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id.'/'.$img.'_'.$language['id_lang'].'.jpg')) {
echo $this->displayError($this->l('An error occured during the image upload.'));
}
}
elseif(isset($_FILES['img_'.$img.'_'.$language['id_lang']]) && $_FILES['img_'.$img.'_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img_'.$img.'_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/'.$sale->id.'/'.$img.'_'.$language['id_lang'].'.jpg')) {
echo $this->displayError($this->l('An error occured during the image upload.'));
}
}
}
}
} elseif(isset($_GET['delete']) && $id_sale = Tools::getValue('id')) {
Sale::deleteSale($id_sale);
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
} elseif(isset($_GET['lock_position']) && $id_sale = Tools::getValue('id')) {
Sale::lockPosition($id_sale);
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
} elseif(isset($_GET['unlock_position']) && $id_sale = Tools::getValue('id')) {
Sale::unlockPosition($id_sale);
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
}
// elseif(isset($_GET['resort_position'])){
// $nb_sales = Db::getInstance()->getValue('
// SELECT COUNT(p.`id_sale`)
// FROM `ps_privatesale` p
// WHERE CAST(p.`date_start` AS DATE) = CAST(NOW() AS DATE)
// AND `date_end` > NOW()
// ');
// if($nb_sales>0) {
// Sale::sortActiveSaleAfterAdd($nb_sales);
// }
// }
}
}