lang = TRUE; parent::__construct(); $this->imagelist = array( 'thumb' => array($this->l('Thumbnail'), '260x108'), 'liston' => array($this->l('Listing image (on)'), '380x178'), 'listoff' => array($this->l('Listing image (off)'), '380x178'), 'fb' => array($this->l('Facebook image'), '100x100'), 'salebg' => array($this->l('Sale background'), '*x*'), '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); echo '
'.$this->l('Edit a sale').''; $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(); echo '
*

'.$this->l('Categories already affected to other sales are greyed.').'

'; echo '

'.$this->l('This value is set by the name of the root category for this sale.').'

'; echo '

'.$this->l('This value is set by the alias of the root category for this sale.').'

'; echo '
*
'; echo '
*
'; echo '
cursale!==NULL?($this->cursale->enabled==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').'   cursale!==NULL?($this->cursale->enabled==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').' *
'; echo '
cursale!==NULL? ($this->cursale->logout==0? ' checked="checked"': ''):' ').' /> '.$this->l('Only for logged in users').'   cursale!==NULL? ($this->cursale->logout==1? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('Show to guests too').' *
'; echo '
cursale!==NULL? ($this->cursale->pub==0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('No').'   cursale!==NULL && $this->cursale->pub==1? ' checked="checked"': '').' /> '.$this->l('Yes').' *
'; echo '
cursale!==NULL? ($this->cursale->braderie==0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('No').'   cursale!==NULL && $this->cursale->braderie ==1? ' checked="checked"': '').' /> '.$this->l('Yes').' *
'; echo '
'; echo '
*
'; echo '
cursale!==NULL? ($this->cursale->new==0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('Non').'   cursale!==NULL && $this->cursale->new==1?' checked="checked"': '').' /> '.$this->l('Oui').' *
'; echo '
cursale!==NULL? ($this->cursale->forward_news==0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('Non').'   cursale!==NULL && $this->cursale->forward_news==1?' checked="checked"': '').' /> '.$this->l('Oui').' *
'; echo '
*
'; $groups = 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 ); echo '
'; $site_versions = array('fr', 'es'/*, 'it'*/); echo '
'; $countries = Country::getCountries($cookie->id_lang, false); echo '
'; // 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 '); $carriers_default = array(22, 87, 88, 89); // prod // $carriers_default = array(22, 46, 47, 48); // dev echo '
'; echo '
cursale!==NULL? ($this->cursale->shipping_fr==0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('Non').'   cursale!==NULL && $this->cursale->shipping_fr==1?' checked="checked"': '').' /> '.$this->l('Oui').' *
'; // } // echo ' //
//
// '.$this->l('SALETYPE1').' cursale->sale_type) && in_array(1,$this->cursale->sale_type) ? ' checked': '') .' type="checkbox" name="sale_type[]" value="1"> // '.$this->l('SALETYPE2').' cursale->sale_type) && in_array(2,$this->cursale->sale_type) ? ' checked': '') .' type="checkbox" name="sale_type[]" value="2"> // '.$this->l('SALETYPE3').' cursale->sale_type) && in_array(3,$this->cursale->sale_type) ? ' checked': '') .' type="checkbox" name="sale_type[]" value="3"> //
//
'; echo '
'; foreach($this->_languages as $language) { echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'description'); echo '
'; echo '
'; foreach($this->_languages as $language) { echo '
cursale !== NULL? ' value="'.htmlentities($this->cursale->video[$language['id_lang']]).'"': '').' />'; echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'video'); echo '

'.$this->l('Youtube full URL').'

'; foreach($this->imagelist as $k => $v) { echo '
'; foreach($this->_languages as $language) { echo '

'.$this->l('Size:').' '.$v[1].'

'; if($this->cursale !== NULL && file_exists(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$this->cursale->id.'/'.$k.'_'.$language['id_lang'].'.jpg')) { echo '

'.$this->l('Preview').'

'; } echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'img_'.$k); echo '
'; } Module::hookExec('privatesales_edit', array('sale' => $this->cursale)); echo '
cursale !== NULL ? 'disabled=disabled': '').' name="submitSaleAdd" value="'.$this->l('Add this sale').'" /> cursale !== NULL? '': ' disabled="disabled"').' id="submitSaleUpdate" />
'; echo '
'; } 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')); } } // // 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']; } //ANTADIS echo '
'; echo 'Tri des ventes'; echo ''; echo ''; echo ''; echo '
'; ?> '; echo '
'.$this->l('Sales list').' '; echo ' '; $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) { echo ' '; if($sale->new == 0){ echo ""; } else if($sale->new == 1){ echo ""; } else if($sale->new == 3){ echo ""; } echo ' '; } echo '
'.$this->l('ID').' '.$this->l('Categorie').' '.$this->l('Title').' '.$this->l('Start').' '.$this->l('End').' '.$this->l('Enabled').' '.$this->l('Nouveau').' '.$this->l('Employee').' '.$this->l('FR').' '.$this->l('ES').' '.$this->l('Shipping').' '.$this->l('News').' '.$this->l('Position').' '.$this->l('Actions').'
'.$sale->id.' '.$sale->id_category.' '.$sale->title[intval($cookie->id_lang)].'
'.$extrafields[$sale->id][1].'
'.$sale->date_start.' '.$sale->date_end.' '.($sale->enabled?'':'').'".$this->l('No')."".$this->l('Yes')."".$this->l('Non défini')."'.((int) $sale->id_employee != 0? $employees[(int) $sale->id_employee]: '--').' versions) ? 'class="green"' : 'class="red"').'>FR versions) ? 'class="green"' : 'class="red"').'>ES '.(isset($sale_shipping[(int) $sale->id])? ($sale_shipping[(int) $sale->id] == 1? 'Philea': ''): '').' '. $sale->forward_news .' '; if($key != 0){ echo 'Haut'; } if($key + 1 != count($sales)){ echo 'Bas'; } $category_link = Link::getCategoryLink($sale->id_category); echo ' '.($export? '': '').'
'; } 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 '
'.Tools::displayError($this->l('Impossible de créer une vente sans transporteur.')).'
'; 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); } foreach(Language::getLanguages(FALSE) as $language) { foreach(array_keys($this->imagelist) as $img) { if((int)$language['id_lang'] == 3 && ($img == 'liston' || $img == 'listoff' || $img == 'thumb') && (!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 '
'.Tools::displayError($this->l('Impossible d\'éditer une vente sans transporteur.')).'
'; 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); } foreach(Language::getLanguages(FALSE) as $language) { foreach(array_keys($this->imagelist) as $img) { if((int)$language['id_lang'] == 3 && ($img == 'liston' || $img == 'listoff' || $img == 'thumb') && (!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')); } } }