lang = TRUE; parent::__construct(); } public function displayForm($isMainTab=TRUE) { global $currentIndex, $cookie; parent::displayForm(); echo '
'.$this->l('Titre du dimanche').''; echo '
FR :
ES :

'; echo '
'; echo '
'; echo '

'; echo '
'.$this->l('Edit a newsletter').''; echo '
'; echo '
'; echo '

'.$this->l('Format: yyyy-mm-dd').'

'; echo '
'; echo '
curnewsletter !== NULL? '': ' disabled="disabled"').' id="submitNewsletterUpdate" />
'; echo '
'; } 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 '
'.$this->l('Vente en avant').'
'; $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 $sale) { echo 'forward_news == 1 ? 'style="background:#f1f1f1"' : ''). '> '; } echo '
forward_news == 1 ? 'checked' : '') .'/>

'; echo '
'.$this->l('Newsletters list').' '; foreach(Db::getInstance()->ExecuteS(' SELECT * FROM `'._DB_PREFIX_.'privatesale_newsletter` ORDER BY `id_newsletter` DESC LIMIT 30 ') as $news) { echo ''; } echo '
'.$this->l('ID').' '.$this->l('Title').' '.$this->l('Date').' '.$this->l('Version').' '.$this->l('Actions').'
'.$news['id_newsletter'].' '.$news['title'].' '.$news['date_pub'].' '.$news['version'].'
'; } function postProcess() { global $cookie, $currentIndex; if(Tools::isSubmit('submitNewsletterAdd')) { $date = Tools::getValue('date_pub'); $now = date('Y-m-d'); $now_seven_more = date('Y-m-d',strtotime($now.' + 7 days')); if($date<$now || $date>$now_seven_more) { $this->_errors[] = Tools::displayError('Vous ne pouvez pas créer une newsletter dans le passé ou dans plus de 7 jours'); } else { 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')).'", "'.pSQL(Tools::getValue('preheader')).'" ) '); $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')).'", `preheader` = "'.pSQL(Tools::getValue('preheader')).'" 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.' '); } } } } }