0) { $fp = fopen('../modules/generate_vouchers/export.csv', 'w'); fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF)); $header = array( 'ID', 'Name', 'Disponibilité', 'Date d\'utilisation' ); fputcsv($fp, $header, ';'); foreach ($vouchers as $voucher) { $fields = array( $voucher['id_discount'], $voucher['name'], $voucher['availibility'], $voucher['date_add'] ); fputcsv($fp, $fields, ';'); } fclose($fp); $this->_html = '
' .$this->l('Export completed') .'
'. $this->l('Export') .'
' .$this->l('This id doesnt exist') .'
'; } } } else if(Tools::isSubmit('submitGenerate')) { if(!empty(Tools::getValue('prefix')) && !empty(Tools::getValue('number')) && !empty(Tools::getValue('title')) ) { // generate vouchers $vouchers = array(); $number = (int)Tools::getValue('number'); $prefix = Tools::getValue('prefix'); $title = Tools::getValue('title'); // add Generation $id_generate_voucher = self::addVoucherGenerate($title, $prefix); if($id_generate_voucher != false) { $params = array( 'value' => (int)Tools::getValue('value'), 'id_currency' => (int)Tools::getValue('id_currency'), 'id_discount_type' => (int)Tools::getValue('id_discount_type'), 'behavior_not_exhausted' => (int)Tools::getValue('behavior_not_exhausted'), 'cumulable' => (int)Tools::getValue('cumulable'), 'cumulable_reduction' => (int)Tools::getValue('cumulable_reduction'), 'minimal' => (int)Tools::getValue('minimal'), 'include_tax' => (int)Tools::getValue('include_tax'), 'quantity' => (int)Tools::getValue('quantity'), 'quantity_per_user' => (int)Tools::getValue('quantity_per_user'), 'date_from' => Tools::getValue('date_from'), 'date_to' => Tools::getValue('date_to'), 'prefix' => Tools::getValue('prefix'), 'description' => Tools::getValue('description_2') ); for ($i=0; $i < $number; $i++) { $discount = $this->_register_discount($params); if(isset($discount->id)) { $vouchers[] = $discount->id; }else{ $this->_html = '' .$this->l('Error') .'
'; } } $sql = 'UPDATE `'._DB_PREFIX_.'generate_vouchers` SET vouchers = "' . json_encode($vouchers) .'" WHERE id_generate = "' . $id_generate_voucher .'"'; if(Db::getInstance()->Execute($sql)) { $this->_html = '' .$this->l('Generation Ok') . '
'; } else { $this->_html = '' .$this->l('Error before generation') .'
'; } } else { $this->_html = '' .$this->l('Error before generation') .'
'; } } else { $this->_html = '' .$this->l('Please, verify information ( required fields)') . '
'; } } } public function display() { global $currentIndex, $cookie; $this->_html .= '' . $this->l('Id') . ' | ' . $this->l('Name') . ' | ' . $this->l('Prefix') . ' | ' . $this->l('Actions') . ' |
---|---|---|---|
'. $voucher['id_generate'] .' | '. $voucher['name'] .' | '. $voucher['prefix'] .' | ' . $this->l('Export') . ' |