From 331d97b48f8d7eec2126c5c60595243b42bced16 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Thu, 23 Jun 2016 19:26:51 +0100 Subject: [PATCH] Added email config to Store Config, added Email_lib, refactored email code (#441, #519) --- application/controllers/Config.php | 21 ++- application/controllers/Sales.php | 44 +++--- application/language/de-CH/config_lang.php | 9 ++ application/language/en/config_lang.php | 9 ++ application/language/es/config_lang.php | 9 ++ application/language/fr/config_lang.php | 9 ++ application/language/hr-HR/config_lang.php | 9 ++ application/language/hu-HU/config_lang.php | 9 ++ application/language/id/config_lang.php | 9 ++ application/language/nl-BE/config_lang.php | 9 ++ application/language/pt-BR/config_lang.php | 9 ++ application/language/ru/config_lang.php | 9 ++ application/language/th/config_lang.php | 9 ++ application/language/tr/config_lang.php | 9 ++ application/language/zh/config_lang.php | 9 ++ application/libraries/Email_lib.php | 49 +++++++ application/views/configs/email_config.php | 141 +++++++++++++++++++ application/views/configs/locale_config.php | 2 +- application/views/configs/manage.php | 38 ++--- application/views/configs/message_config.php | 4 +- database/2.4_to_3.0.sql | 7 +- database/database.sql | 7 +- database/migrate_phppos_dist.sql | 7 +- database/tables.sql | 7 +- translations/config_lang.csv | 9 ++ 25 files changed, 408 insertions(+), 45 deletions(-) create mode 100644 application/libraries/Email_lib.php create mode 100644 application/views/configs/email_config.php diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 4c40feea3..248b4b45b 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -108,7 +108,26 @@ class Config extends Secure_Controller echo json_encode(array('success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); } - + + public function save_email() + { + $batch_save_data = array( + 'protocol' => $this->input->post('protocol'), + 'mailpath' => $this->input->post('mailpath'), + 'smtp_host' => $this->input->post('smtp_host'), + 'smtp_user' => $this->input->post('smtp_user'), + 'smtp_pass' => $this->input->post('smtp_pass'), + 'smtp_port' => $this->input->post('smtp_port'), + 'smtp_timeout' => $this->input->post('smtp_timeout'), + 'smtp_crypto' => $this->input->post('smtp_crypto') + ); + + $result = $this->Appconfig->batch_save($batch_save_data); + $success = $result ? TRUE : FALSE; + + echo json_encode(array('success' => $success, 'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully'))); + } + public function save_message() { $batch_save_data = array( diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 53f973409..8d18c9576 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -10,6 +10,7 @@ class Sales extends Secure_Controller $this->load->library('sale_lib'); $this->load->library('barcode_lib'); + $this->load->library('email_lib'); } public function index() @@ -413,32 +414,32 @@ class Sales extends Secure_Controller $result = FALSE; $message = $this->lang->line('sales_invoice_no_email'); - if(isset($sale_data["customer_email"]) && !empty($sale_data["customer_email"])) + + if(!empty($sale_data['customer_email'])) { - $this->load->library('email'); - $this->email->from($this->config->item('email'), $this->config->item('company')); - $this->email->to($sale_data['customer_email']); - $this->email->subject($this->lang->line('sales_invoice') . ' ' . $sale_data['invoice_number']); + $to = $sale_data['customer_email']; + $subject = $this->lang->line('sales_invoice') . ' ' . $sale_data['invoice_number']; + $text = $this->config->item('invoice_email_message'); $text = str_replace('$INV', $sale_data['invoice_number'], $text); $text = str_replace('$CO', 'POS ' . $sale_data['sale_id'], $text); - $text = $this->_substitute_customer($text,(object) $sale_data); - $this->email->message($text); + $text = $this->_substitute_customer($text, (object) $sale_data); // generate email attachment: invoice in pdf format $html = $this->load->view('sales/invoice_email', $sale_data, TRUE); // load pdf helper $this->load->helper(array('dompdf', 'file')); $file_content = pdf_create($html, '', FALSE); - $filename = sys_get_temp_dir() . '/'. $this->lang->line('sales_invoice') . '-' . str_replace('/', '-' , $sale_data["invoice_number"]) . '.pdf'; + $filename = sys_get_temp_dir() . '/' . $this->lang->line('sales_invoice') . '-' . str_replace('/', '-' , $sale_data['invoice_number']) . '.pdf'; write_file($filename, $file_content); + + $result = $this->email_lib->sendEmail($to, $subject, $text, $filename); - $this->email->attach($filename); - $result = $this->email->send(); - $message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $sale_data["customer_email"]; + $message = $this->lang->line($result ? 'sales_invoice_sent' : 'sales_invoice_unsent') . ' ' . $to; } echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); + $this->sale_lib->clear_all(); return $result; @@ -450,22 +451,23 @@ class Sales extends Secure_Controller $result = FALSE; $message = $this->lang->line('sales_receipt_no_email'); - if(isset($sale_data["customer_email"]) && !empty( $sale_data["customer_email"])) + + if(!empty($sale_data['customer_email'])) { $sale_data['barcode'] = $this->barcode_lib->generate_receipt_barcode($sale_data['sale_id']); - $this->load->library('email'); - $config['mailtype'] = 'html'; - $this->email->initialize($config); - $this->email->from($this->config->item('email'), $this->config->item('company')); - $this->email->to($sale_data['customer_email']); - $this->email->subject($this->lang->line('sales_receipt')); - $this->email->message($this->load->view('sales/receipt_email', $sale_data, TRUE)); - $result = $this->email->send(); - $message = $this->lang->line($result ? 'sales_receipt_sent' : 'sales_receipt_unsent') . ' ' . $sale_data["customer_email"]; + $to = $sale_data['customer_email']; + $subject = $this->lang->line('sales_receipt'); + + $text = $this->load->view('sales/receipt_email', $sale_data, TRUE); + + $result = $this->email_lib->sendEmail($to, $subject, $text); + + $message = $this->lang->line($result ? 'sales_receipt_sent' : 'sales_receipt_unsent') . ' ' . $to; } echo json_encode(array('success' => $result, 'message' => $message, 'id' => $sale_id)); + $this->sale_lib->clear_all(); return $result; diff --git a/application/language/de-CH/config_lang.php b/application/language/de-CH/config_lang.php index b1ad3692f..d7cf47f40 100644 --- a/application/language/de-CH/config_lang.php +++ b/application/language/de-CH/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "MWSt 2"; $lang["config_default_tax_rate_number"] = "MWSt Rate"; $lang["config_default_tax_rate_required"] = "MWSt ist erforderlich"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "Einstellungen"; $lang["config_general_configuration"] = "Einstellungen"; diff --git a/application/language/en/config_lang.php b/application/language/en/config_lang.php index e1742030c..75ca576be 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Tax 2 Rate"; $lang["config_default_tax_rate_number"] = "The default tax rate must be a number"; $lang["config_default_tax_rate_required"] = "The default tax rate is a required field"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/language/es/config_lang.php b/application/language/es/config_lang.php index e05a9d94d..acd0bfdd6 100644 --- a/application/language/es/config_lang.php +++ b/application/language/es/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Impuesto 2"; $lang["config_default_tax_rate_number"] = "El Impuesto Predeterminado debe ser un número"; $lang["config_default_tax_rate_required"] = "El Impuesto Predeterminado es requerido"; $lang["config_default_tax_name_required"] = "El nombre del impuesto predeterminado es requerido"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "Configuración General"; diff --git a/application/language/fr/config_lang.php b/application/language/fr/config_lang.php index b1c656f1a..d35acd227 100644 --- a/application/language/fr/config_lang.php +++ b/application/language/fr/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Taux d'Imposition 2"; $lang["config_default_tax_rate_number"] = "Le taux d'imposition doit etre un nombre"; $lang["config_default_tax_rate_required"] = "Le taux d'imposition par défaut est requis"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/language/hr-HR/config_lang.php b/application/language/hr-HR/config_lang.php index 6128e74a8..a7e7a0b26 100644 --- a/application/language/hr-HR/config_lang.php +++ b/application/language/hr-HR/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Porez 2 %"; $lang["config_default_tax_rate_number"] = "Zadani porez mora biti broj"; $lang["config_default_tax_rate_required"] = "Zadani porez je potreban"; $lang["config_default_tax_name_required"] = "Naziv poreza je poteban"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "Opća"; $lang["config_general_configuration"] = "Opća konfiguracija"; diff --git a/application/language/hu-HU/config_lang.php b/application/language/hu-HU/config_lang.php index 0d78909e7..af5e0f4ff 100644 --- a/application/language/hu-HU/config_lang.php +++ b/application/language/hu-HU/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Adó 2"; $lang["config_default_tax_rate_number"] = "Az alapértelmezett adónak számnak kell lennie"; $lang["config_default_tax_rate_required"] = "Az alapértelmezett adó kötelező mező"; $lang["config_default_tax_name_required"] = "Alapértelmezett adó név kötelező mező"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "Általános"; $lang["config_general_configuration"] = "Általános beállitás"; diff --git a/application/language/id/config_lang.php b/application/language/id/config_lang.php index d80e37646..8d7daa889 100644 --- a/application/language/id/config_lang.php +++ b/application/language/id/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Tarif Pajak 2"; $lang["config_default_tax_rate_number"] = "Tarif Pajak Biasa harus angka"; $lang["config_default_tax_rate_required"] = "Tarif Pajak Biasa wajib diisi"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/language/nl-BE/config_lang.php b/application/language/nl-BE/config_lang.php index 66c62401a..7210afa3c 100755 --- a/application/language/nl-BE/config_lang.php +++ b/application/language/nl-BE/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "VAT 2 %"; $lang["config_default_tax_rate_number"] = "Het percentage VAT moet een nummer zijn"; $lang["config_default_tax_rate_required"] = "Het percentage VAT moet ingevuld worden"; $lang["config_default_tax_name_required"] = "De naam van de VAT moet ingevuld worden"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "Algemene"; $lang["config_general_configuration"] = "Algemene Instellingen"; diff --git a/application/language/pt-BR/config_lang.php b/application/language/pt-BR/config_lang.php index 3f985f520..e878f7f59 100644 --- a/application/language/pt-BR/config_lang.php +++ b/application/language/pt-BR/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Imposto 2 Tarifa"; $lang["config_default_tax_rate_number"] = "A taxa de Imposto padrão deve ser um número"; $lang["config_default_tax_rate_required"] = "A taxa de Imposto padrão é um campo obrigatório"; $lang["config_default_tax_name_required"] = "Nome da taxa padrão é requerida"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Fax"; $lang["config_general"] = "Gerais"; $lang["config_general_configuration"] = "Configurações Gerais"; diff --git a/application/language/ru/config_lang.php b/application/language/ru/config_lang.php index 52263a0ef..4c9675779 100644 --- a/application/language/ru/config_lang.php +++ b/application/language/ru/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "ставка налога 2"; $lang["config_default_tax_rate_number"] = "Обычный ставка налога должен быть цифра"; $lang["config_default_tax_rate_required"] = "Обычный ставка налога обязательный пробел"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Факс"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/language/th/config_lang.php b/application/language/th/config_lang.php index 0a6a5ce3e..104a23ceb 100644 --- a/application/language/th/config_lang.php +++ b/application/language/th/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "อัตราภาษี 2"; $lang["config_default_tax_rate_number"] = "อัตราภาษีเริ่มต้นต้องเป็นตัวเลข"; $lang["config_default_tax_rate_required"] = "อัตราภาษีเริ่มต้นต้องกรอก"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "แฟ็กซ์"; $lang["config_general"] = "ตั้งค่าทั่วไป"; $lang["config_general_configuration"] = "ตั้งค่าทั่วไป"; diff --git a/application/language/tr/config_lang.php b/application/language/tr/config_lang.php index 828efdb77..4084eb0ae 100644 --- a/application/language/tr/config_lang.php +++ b/application/language/tr/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "Vergi Oranı 2"; $lang["config_default_tax_rate_number"] = "Varsayılan Vergi Oranı sayı olmalıdır"; $lang["config_default_tax_rate_required"] = "Varsayılan Vergi Oranı zorunlu alandır"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "Faks"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/language/zh/config_lang.php b/application/language/zh/config_lang.php index b5fdc501b..deaa7e28e 100755 --- a/application/language/zh/config_lang.php +++ b/application/language/zh/config_lang.php @@ -70,6 +70,15 @@ $lang["config_default_tax_rate_2"] = "稅率 2"; $lang["config_default_tax_rate_number"] = "預設稅率必需為數字"; $lang["config_default_tax_rate_required"] = "預設稅率為必填"; $lang["config_default_tax_name_required"] = "The default tax name is a required field"; +$lang["config_email"] = "Email"; +$lang["config_email_protocol"] = "Protocol"; +$lang["config_email_mailpath"] = "Path to Sendmail"; +$lang["config_email_smtp_host"] = "SMTP Server"; +$lang["config_email_smtp_port"] = "SMTP Port"; +$lang["config_email_smtp_crypto"] = "SMTP Encryption"; +$lang["config_email_smtp_timeout"] = "SMTP Timeout (s)"; +$lang["config_email_smtp_user"] = "SMTP Username"; +$lang["config_email_smtp_pass"] = "SMTP Password"; $lang["config_fax"] = "傳真"; $lang["config_general"] = "General"; $lang["config_general_configuration"] = "General Configuration"; diff --git a/application/libraries/Email_lib.php b/application/libraries/Email_lib.php new file mode 100644 index 000000000..7cb6f2a14 --- /dev/null +++ b/application/libraries/Email_lib.php @@ -0,0 +1,49 @@ +CI =& get_instance(); + + $this->CI->load->library('email'); + + $config = array( + 'mailtype' => 'html', + 'useragent' => 'OSPOS', + 'validate' => TRUE, + 'protocol' => $this->CI->config->item('protocol'), + 'mailpath' => $this->CI->config->item('mailpath'), + 'smtp_host' => $this->CI->config->item('smtp_host'), + 'smtp_user' => $this->CI->config->item('smtp_user'), + 'smtp_pass' => $this->CI->config->item('smtp_pass'), + 'smtp_port' => $this->CI->config->item('smtp_port'), + 'smtp_timeout' => $this->CI->config->item('smtp_timeout'), + 'smtp_crypto' => $this->CI->config->item('smtp_crypto') + ); + + $this->CI->email->initialize($config); + } + + /* + * Email sending function + * Example of use: $response = sendEmail('john@doe.com', 'Hello', 'This is a message', $filename); + */ + public function sendEmail($to, $subject, $message, $attachment = NULL) + { + $this->CI->email->from($this->CI->config->item('email'), $this->CI->config->item('company')); + $this->CI->email->to($to); + $this->CI->email->subject($subject); + $this->CI->email->message($message); + if( !empty($attachment) ) + { + $this->CI->email->attach($attachment); + } + + return $this->CI->email->send(); + } +} + +?> diff --git a/application/views/configs/email_config.php b/application/views/configs/email_config.php new file mode 100644 index 000000000..a592446f1 --- /dev/null +++ b/application/views/configs/email_config.php @@ -0,0 +1,141 @@ + 'email_config_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?> +
+
+
lang->line('common_fields_required_message'); ?>
+
    + +
    + lang->line('config_email_protocol'), 'protocol', array('class' => 'control-label col-xs-2')); ?> +
    + 'mail', + 'sendmail' => 'sendmail', + 'smtp' => 'smtp' + ), + $this->config->item('protocol'), array('class' => 'form-control input-sm', 'id' => 'protocol')); + ?> +
    +
    + +
    + lang->line('config_email_mailpath'), 'mailpath', array('class' => 'control-label col-xs-2')); ?> +
    + 'mailpath', + 'id' => 'mailpath', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('mailpath'))); ?> +
    +
    + +
    + lang->line('config_email_smtp_host'), 'smtp_host', array('class' => 'control-label col-xs-2')); ?> +
    + 'smtp_host', + 'id' => 'smtp_host', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('smtp_host'))); ?> +
    +
    + +
    + lang->line('config_email_smtp_port'), 'smtp_port', array('class' => 'control-label col-xs-2')); ?> +
    + 'smtp_port', + 'id' => 'smtp_port', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('smtp_port'))); ?> +
    +
    + +
    + lang->line('config_email_smtp_crypto'), 'smtp_crypto', array('class' => 'control-label col-xs-2')); ?> +
    + 'None', + 'tls' => 'TLS', + 'ssl' => 'SSL' + ), + $this->config->item('smtp_crypto'), array('class' => 'form-control input-sm', 'id' => 'smtp_crypto')); + ?> +
    +
    + +
    + lang->line('config_email_smtp_timeout'), 'smtp_timeout', array('class' => 'control-label col-xs-2')); ?> +
    + 'smtp_timeout', + 'id' => 'smtp_timeout', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('smtp_timeout'))); ?> +
    +
    + +
    + lang->line('config_email_smtp_user'), 'smtp_user', array('class' => 'control-label col-xs-2')); ?> +
    +
    + + 'smtp_user', + 'id' => 'smtp_user', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('smtp_user'))); ?> +
    +
    +
    + +
    + lang->line('config_email_smtp_pass'), 'smtp_pass', array('class' => 'control-label col-xs-2')); ?> +
    +
    + + 'smtp_pass', + 'id' => 'smtp_pass', + 'class' => 'form-control input-sm', + 'value' => $this->config->item('smtp_pass'))); ?> +
    +
    +
    + + 'submit_form', + 'id' => 'submit_form', + 'value' => $this->lang->line('common_submit'), + 'class' => 'btn btn-primary btn-sm pull-right')); ?> +
    +
    + + + diff --git a/application/views/configs/locale_config.php b/application/views/configs/locale_config.php index 54b59fe21..6d27cd97c 100644 --- a/application/views/configs/locale_config.php +++ b/application/views/configs/locale_config.php @@ -105,7 +105,7 @@ -
    +
    lang->line('config_country_codes'), 'country_codes', array('class'=>'control-label col-xs-2')); ?>
    config->item('country_codes'), array('class'=>'form-control input-sm')); ?> diff --git a/application/views/configs/manage.php b/application/views/configs/manage.php index efca39f32..b352ad7d6 100644 --- a/application/views/configs/manage.php +++ b/application/views/configs/manage.php @@ -2,54 +2,60 @@
    -
    +
    load->view("configs/info_config"); ?>
    -
    +
    load->view("configs/general_config"); ?>
    -
    +
    load->view("configs/locale_config"); ?>
    -
    +
    load->view("configs/barcode_config"); ?>
    -
    +
    load->view("configs/stock_config"); ?>
    -
    +
    load->view("configs/receipt_config"); ?>
    -
    +
    load->view("configs/invoice_config"); ?>
    -
    +
    + load->view("configs/email_config"); ?> +
    +
    load->view("configs/message_config"); ?>
    diff --git a/application/views/configs/message_config.php b/application/views/configs/message_config.php index 43967a455..48acd7b1e 100755 --- a/application/views/configs/message_config.php +++ b/application/views/configs/message_config.php @@ -2,7 +2,7 @@
    lang->line('common_fields_required_message'); ?>
    -
      +
        lang->line('config_msg_uid'), 'msg_uid', array('class'=>'control-label col-xs-2 required')); ?> @@ -73,7 +73,7 @@ $(document).ready(function() { $('#message_config_form').validate($.extend(form_support.handler, { - errorLabelContainer: "#general_error_message_box", + errorLabelContainer: "#message_error_message_box", rules: { diff --git a/database/2.4_to_3.0.sql b/database/2.4_to_3.0.sql index 93aaae8c7..8a3eeeec6 100644 --- a/database/2.4_to_3.0.sql +++ b/database/2.4_to_3.0.sql @@ -46,7 +46,12 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('country_codes', 'us'), ('notify_horizontal_position', 'right'), ('notify_vertical_position', 'top'), - ('payment_options_order', 'cashdebitcredit'); + ('payment_options_order', 'cashdebitcredit'), + ('protocol', 'mail'), + ('mailpath', '/usr/sbin/sendmail'), + ('smtp_port', '465'), + ('smtp_timeout', '5'), + ('smtp_crypto', 'ssl'); DELETE FROM `ospos_app_config` WHERE `key` = 'use_invoice_template'; diff --git a/database/database.sql b/database/database.sql index 46c62be5a..d3ce2ee6d 100644 --- a/database/database.sql +++ b/database/database.sql @@ -71,7 +71,12 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('msg_pwd', ''), ('notify_horizontal_position', 'right'), ('notify_vertical_position', 'top'), -('payment_options_order', 'cashdebitcredit'); +('payment_options_order', 'cashdebitcredit'), +('protocol', 'mail'), +('mailpath', '/usr/sbin/sendmail'), +('smtp_port', '465'), +('smtp_timeout', '5'), +('smtp_crypto', 'ssl'); -- -------------------------------------------------------- diff --git a/database/migrate_phppos_dist.sql b/database/migrate_phppos_dist.sql index be72f5a9e..fb63ca5e7 100644 --- a/database/migrate_phppos_dist.sql +++ b/database/migrate_phppos_dist.sql @@ -71,7 +71,12 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('msg_pwd', ''), ('notify_horizontal_position', 'right'), ('notify_vertical_position', 'top'), -('payment_options_order', 'cashdebitcredit'); +('payment_options_order', 'cashdebitcredit'), +('protocol', 'mail'), +('mailpath', '/usr/sbin/sendmail'), +('smtp_port', '465'), +('smtp_timeout', '5'), +('smtp_crypto', 'ssl'); -- -------------------------------------------------------- diff --git a/database/tables.sql b/database/tables.sql index ac7c9ed31..38cdfffd1 100644 --- a/database/tables.sql +++ b/database/tables.sql @@ -71,7 +71,12 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('msg_pwd', ''), ('notify_horizontal_position', 'right'), ('notify_vertical_position', 'top'), -('payment_options_order', 'cashdebitcredit'); +('payment_options_order', 'cashdebitcredit'), +('protocol', 'mail'), +('mailpath', '/usr/sbin/sendmail'), +('smtp_port', '465'), +('smtp_timeout', '5'), +('smtp_crypto', 'ssl'); -- -------------------------------------------------------- diff --git a/translations/config_lang.csv b/translations/config_lang.csv index be0211a7b..9afe7620b 100644 --- a/translations/config_lang.csv +++ b/translations/config_lang.csv @@ -69,6 +69,15 @@ config_default_tax_rate_2,Adó 2,MWSt 2,VAT 2 %,Impuesto 2,Tax 2 Rate,Taux d'Imp config_default_tax_rate_number,Az alapértelmezett adónak számnak kell lennie,MWSt Rate,Het percentage VAT moet een nummer zijn,El Impuesto Predeterminado debe ser un número,The default tax rate must be a number,Le taux d'imposition doit etre un nombre,預設稅率必需為數字,Обычный ставка налога должен быть цифра,อัตราภาษีเริ่มต้นต้องเป็นตัวเลข,Varsayılan Vergi Oranı sayı olmalıdır,Tarif Pajak Biasa harus angka,A taxa de Imposto padrão deve ser um número,Zadani porez mora biti broj config_default_tax_rate_required,Az alapértelmezett adó kötelező mező,MWSt ist erforderlich,Het percentage VAT moet ingevuld worden,El Impuesto Predeterminado es requerido,The default tax rate is a required field,Le taux d'imposition par défaut est requis,預設稅率為必填,Обычный ставка налога обязательный пробел,อัตราภาษีเริ่มต้นต้องกรอก,Varsayılan Vergi Oranı zorunlu alandır,Tarif Pajak Biasa wajib diisi,A taxa de Imposto padrão é um campo obrigatório,Zadani porez je potreban config_default_tax_name_required,Alapértelmezett adó név kötelező mező,The default tax name is a required field,De naam van de VAT moet ingevuld worden,El nombre del impuesto predeterminado es requerido,The default tax name is a required field,The default tax name is a required field,The default tax name is a required field,The default tax name is a required field,The default tax name is a required field,The default tax name is a required field,The default tax name is a required field,Nome da taxa padrão é requerida,Naziv poreza je poteban +config_email,Email,Email,Email,Email,Email,Email,Email,Email,Email,Email,Email,Email,Email +config_email_protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol,Protocol +config_email_mailpath,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail,Path to Sendmail +config_email_smtp_host,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server,SMTP Server +config_email_smtp_port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port,SMTP Port +config_email_smtp_crypto,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption,SMTP Encryption +config_email_smtp_timeout,SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s),SMTP Timeout (s) +config_email_smtp_user,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username,SMTP Username +config_email_smtp_pass,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password,SMTP Password config_fax,Fax,Fax,Fax,Fax,Fax,Fax,傳真,Факс,แฟ็กซ์,Faks,Fax,Fax,Fax config_general,Általános,Einstellungen,Algemene,General,General,General,General,General,ตั้งค่าทั่วไป,General,General,Gerais,Opća config_general_configuration,Általános beállitás,Einstellungen,Algemene Instellingen,Configuración General,General Configuration,General Configuration,General Configuration,General Configuration,ตั้งค่าทั่วไป,General Configuration,General Configuration,Configurações Gerais,Opća konfiguracija