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*'), 'mobile' => array($this->l('Listing App'), '900*450px'), //'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 .=' '; $helperForm->_css .=''; echo $helperForm->renderStyle(); $helperForm->_forms = array( array( 'action' => $base_link, 'title' => $this->l('Création Catégorie principale'), 'icon' => ' ', 'class' => 'form-horizontal', 'id' => 'form-category', 'class_div' => 'col-md-12', //'information' => 'Création catégorie principale', 'sections' => array( array( 'inputs' => array( array( 'type' => 'simpleText', 'label' => $this->l('Catégorie : '), 'label-class' => 'col-md-2', 'input-class' => 'col-md-6', 'name' => 'category', ), array( 'type' => 'uploadImage', 'label' => $this->l('Logo : '), 'label-class' => 'col-md-2', 'input-class' => 'col-md-6', 'name' => 'image_thumb', 'id' => 'preview_thumb', ), array( 'type' => 'uploadImage', 'label' => $this->l('Image Latérale : '), 'label-class' => 'col-md-2', 'input-class' => 'col-md-6', 'name' => 'image_category', 'id' => 'preview_category', ), ), ), ), 'actions' => array( array( 'type' => 'submit', 'class' => 'btn-primary', 'name' => 'submitCategoryAdd', 'value' => $this->l('Ajouter') ) ), 'actions-class' => 'text-right', ), ); echo '
'.$helperForm->renderForm(false, NULL, NULL, true).'
'; $helperForm->_forms = array(); $helperForm->_html = ''; 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(); 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 .= ''; echo '
'; // 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 '
'; // 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 '
'; // 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 '
'; // 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' => '', 'value' => ($this->cursale!==NULL? $this->cursale->date_start: ''), 'required' => true, ); echo $helperForm->generateInput($input); echo '
'; // 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' => '', 'value' => ($this->cursale!==NULL? $this->cursale->date_end: ''), 'required' => true, ); echo $helperForm->generateInput($input); echo '
'; echo '
'; // Status $input = array( 'type' => 'switch', 'name' => 'enabled', 'label' => $this->l('Active :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Display $input = array( 'type' => 'switch', 'name' => 'logout', 'label' => $this->l('Affichage non inscrits :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Public $input = array( 'type' => 'switch', 'name' => 'pub', 'label' => $this->l('Public sale:'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Braderie $input = array( 'type' => 'switch', 'name' => 'braderie', 'label' => $this->l('Braderie :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Uncombinable $input = array( 'type' => 'switch', 'name' => 'uncombinable', 'label' => $this->l('Non cumulable :'), // 'label_on' => '', // 'label_off' => '', 'label-class' => 'col-sm-8', 'input-class' => 'col-sm-4', 'default' => ($this->cursale!==NULL?($this->cursale->uncombinable==0?0:1):0), 'checked' => ($this->cursale!==NULL?($this->cursale->uncombinable==0?0:1):0), 'required' => true, ); echo $helperForm->generateInput($input); echo '
'; // Featured $input = array( 'type' => 'switch', 'name' => 'featured', 'label' => $this->l('Featured sale:'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // New $input = array( 'type' => 'switch', 'name' => 'new', 'label' => $this->l('Nouveau :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Newsletter $input = array( 'type' => 'switch', 'name' => 'forward_news', 'label' => $this->l('Mise en avant Newsletter :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; // Shipping only fr $input = array( 'type' => 'switch', 'name' => 'shipping_fr', 'label' => $this->l('Livraison seulement en France :'), // 'label_on' => '', // 'label_off' => '', '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 '
'; $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 '
'; $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== 9?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 '
'; $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 '
'; $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 '
'; $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 '
'; // 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 '
'; // 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 '
'; // 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 '
'; Module::hookExec('privatesales_edit', array('sale' => $this->cursale)); echo '

Images

'; 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 '
'; } $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 '
'; echo '
cursale !== NULL ? 'disabled=disabled': '').' name="submitSaleAdd" value="'.$this->l('Add this sale').'" /> cursale !== NULL? '': ' disabled="disabled"').' id="submitSaleUpdate" />
'; echo '
'; 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']; } ?> '; 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) { $delay = SaleDelay::getDelaySmallName($sale->delivery_delay,2); echo ' '; if($sale->new == 0){ echo ""; } else if($sale->new == 1){ echo ""; } else if($sale->new == 3){ echo ""; } echo ' '; // '.($export? '': '').' // // // // // } echo '
'.$this->l('ID').' '.$this->l('Cat.').' '.$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('Delay').' '.$this->l('Expe').' '.$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]: '--').' FR ES '.$delay.' '.(isset($sale_shipping[(int) $sale->id])? ($sale_shipping[(int) $sale->id] == 1? 'Philéa': ($sale_shipping[(int) $sale->id] == 2? 'Drop' : '')): '').' '. $sale->forward_news .' '; if($sale->lock_position == 1){ echo ''; } else { if($key != 0){ echo 'Haut'; } if($key + 1 != count($sales)){ echo ' Bas'; } } $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 '
'; } 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('submitCategoryAdd')) { $date = date('Y') . '-' . date('m'); $name = Tools::getValue('category'); $meta_name = 'Vente privée '.$name; $meta_name_es = 'Venta privada '.$name; $category = new Category(); $category->id_parent = 1; $category->active = 1; $category->name[2] = $name; $category->name[3] = $name; $category->description[2] = $date; $category->description[3] = $date; $category->meta_title[2] = $meta_name; $category->meta_title[3] = $meta_name_es; $category->meta_keywords[2] = $meta_name; $category->meta_keywords[3] = $meta_name_es; $category->meta_description[2] = $meta_name; $category->meta_description[3] = $meta_name_es; $category->link_rewrite[2] = $this->str2url($name); $category->link_rewrite[3] = $category->link_rewrite[2]; $category->groupBox = $groups; if($category->add()) { if (isset($_FILES['image_thumb']) && $_FILES['image_thumb']['name'] != NULL) { copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp_2.jpg'); copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp_3.jpg'); } // if (isset($_FILES['image_mobile']) && $_FILES['image_mobile']['name'] != NULL) { // copy($_FILES['image_mobile']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_mobile_vp_2.jpg'); // copy($_FILES['image_mobile']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_mobile_vp_3.jpg'); // } if (isset($_FILES['image_category']) && $_FILES['image_category']['name'] != NULL) { copy($_FILES['image_category']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'.jpg'); if (file_exists(_PS_CAT_IMG_DIR_.$category->id.'.jpg')) { $imagesTypes = ImageType::getImagesTypes('categories'); foreach ($imagesTypes AS $k => $imageType) { imageResize(_PS_CAT_IMG_DIR_.$category->id.'.jpg', _PS_CAT_IMG_DIR_.$category->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); } } } Category::regenerateEntireNtree(); HelperFormBootstrap::echoConfirmation('Catégorie créée Voir '); } else { HelperFormBootstrap::echoError('Un problème est survenue lors de la création de catégorie'); } } elseif(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->uncombinable = Tools::getValue('uncombinable', 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); } $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' || $img == 'mobile') && (!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->uncombinable = Tools::getValue('uncombinable', 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); } $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); // } // } } public function str2url($string, $slug = '-', $extra = null) { return strtolower(trim(preg_replace('~[^0-9a-z' . preg_quote($extra, '~') . ']+~i', $slug, $this->unaccent($string)), $slug)); } public function unaccent($string) // normalizes (romanization) accented chars { if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) { $string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8'); } return $string; } }