Hi
i have a module called pagseguro quite similar to paypal and i use zen-cart 1.3.7

It works fine but has a little bug .
when i receive the order confirmation email there is something wrong
the email variables cannot be read by the template language file (i'm using portugues language as default) and they appear like this

EMAIL_THANKS_FOR_SHOPPING
EMAIL_DETAILS_FOLLOW
EMAIL_SEPARATOR
EMAIL_TEXT_ORDER_NUMBER 37
EMAIL_TEXT_DATE_ORDERED sábado 31 maio, 2008
EMAIL_TEXT_INVOICE_URL

and so on....

The module sends the translated variables only when i switch the language to english.
I tried to modify in every single way as suggested into similar threads but nothing...

I changed the charset into languages/portugues.php to

define('CHARSET', 'iso-8859-1');
I went to functions_email.php and tried to modify

$lang_code = strtolower(($_SESSION['languages_code'] == '' ? 'en' : $_SESSION['languages_code'] ));
to

$lang_code = strtolower(($_SESSION['languages_code'] == '' ? 'en' or 'pt': $_SESSION['languages_code'] ));
Tryed to change email format from text to html also but nothing

this was all useless................
Probably the error is into $_SESSION variable but i really don't know how to handle it
I paste the code of the module and hope that someone could give some hint.
I'd pay even some freelance coder to solve this problem for a reasonable price if no one can see a solution ...

THANK YOU!

<?php
/*
* Módulo de Pagamento Zen-Cart 3.7 para pagamentos através do BRPay
* Autor: Marcus Moreira de Souza <marcus.moreira######################>
* Derivado da versão de: Claudio H. Imai <[email protected]>
*
* Esse script é utilizado para o retorno automático do BRPay.
* Ele será requisitado duas vezes após o cliente efetuar o pagamento no site do BRPay.
* Na primeira requisição, o script receberá os dados do pagamento via POST, validará junto ao
* BRPay as informações recebidas e registrará na tabela 'temp_brpay'.
* A segunda requisição será um GET, que redirecionará o usuário a página de confirmação de
* pagamento (index.php?main_page=checkout_success)
*
* @package paymentMethod
* @copyright 2007 Marcus Moreira de Souza <marcus.moreira######################>
* @copyright 2006 Creativstudios Web Solutions <[email protected]>
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.0
*/


//chdir('../../../');
require('includes/application_top.php');

if (!function_exists('debug_var'))
{
function debug_var($var, $name='', $to_file=false)
{
if ($to_file==true) {
$txt = fopen('log/debug-brpay-retorno.log','a');
fwrite($txt, "-----------------------------------\n");
fwrite($txt, $name."\n");
fwrite($txt, print_r($var, true)."\n");
fclose($txt);//
} else {
print('<pre><br><b>'.$name.'</b><br>');
echo '<pre>';
print_r($var);
echo '</pre>';
}
}
}



// re-set the level of error reporting due to problems with IIS and the loop fgets
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
debug_var ($_POST, "POST recebido (A): ".date("Y-m-d G:i:s"), true);

// RECEBE O POST ENVIADO PELA BRPAY E ADICIONA OS VALORES PARA VALIDACAO DOS DADOS

if (!zen_not_null($_POST)) { // variaveis POST vazias, significa que eh a segunda chamada do script
debug_var ('Redirecionando para index.php?main_page=checkout_success', "POST vazio: ".date("Y-m-d G:i:s"), true);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, "", 'SSL'));
}

debug_var ($_POST, "POST recebido: ".date("Y-m-d G:i:s"), true);

// ENVIA DE VOLTA PARA A BRPAY OS DADOS PARA VALIDACAO
$BRpay = 'Comando=validar';
$BRpay .= "&Token=".trim(MODULE_PAYMENT_BRPAY_TOKEN);

foreach ($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$BRpay .= "&$key=$value";
}

$server = 'www.brpay.com.br';
$fsocket = false;
$curl = false;
$result = false;

if (function_exists('curl_exec')) {
$curl = true;
} elseif ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen ('ssl://'.$server, 443, $errno, $errstr, 30)) ) {
$fsocket = true;
} elseif ($fp = @fsockopen($server, 80, $errno, $errstr, 30)) {
$fsocket = true;
}

$confirma = false;

if ($curl == true) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://' . $server . '/Security/NPI/Default.aspx');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $BRpay);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($ch);
if (!zen_not_null($resp)) {
curl_setopt($ch, CURLOPT_URL, 'http://' . $server . '/Security/NPI/Default.aspx');
$resp = curl_exec($ch);
}
debug_var ($resp, "Resposta da requisicao cURL: ".date("Y-m-d G:i:s"),true);

curl_close($ch);
$confirma = (strcmp ($resp, "VERIFICADO") == 0);

} elseif ($fsocket == true) {
$Cabecalho = "POST /Security/NPI/Default.aspx HTTP/1.0\r\n";
$Cabecalho .= "Content-Type: application/x-www-form-urlencoded\r\n";
$Cabecalho .= "Content-Length: " . strlen($BRpay) . "\r\n\r\n";

if ($fp || $errno>0){
fputs ($fp, $Cabecalho . $BRpay);
$resp = '';
while (!feof($fp)){
$res = @fgets ($fp, 1024);
$resp .= $res;
// Verifica se o status da transacao esta VERIFICADO
if (strcmp ($res, "VERIFICADO") == 0)
{
$confirma=true;
debug_var ($resp, "fsockopen: ".date("Y-m-d G:i:s"),true);
break;
}
}
fclose ($fp);
} else{
echo "$errstr ($errno)<br />\n";
debug_var ($errstr.'('.$errno.')', "erro em fsockopen:: ".date("Y-m-d G:i:s"),true);
// ERRO HTTP
}
}

debug_var ($resp.'<br>resultado da confirmacao: '.print_r($confirma,true), "resposta: ".date("Y-m-d G:i:s"),true);

if ($confirma) {
// Verifique se a TransacaoID nao foi previamente processada
// Verifique se o email recebido (VendedorEmail) eh o seu email
// Verifique se o valor do pagamento esta correto
// Processe o pagamento salvando os dados em seu banco de dados
// RECEBE OS DADOS ENVIADOS PELA BRPAY E ARMAZENA EM VARIAVEIS
$DataTransacao = $_POST['DataTransacao'];
$DataHora = substr($DataTransacao,6,4)."-".substr($DataTransacao,3,2)."-".substr($DataTransacao,0,2)."-".substr($DataTransacao,10,9);
$sql_data_array = array('VendedorEmail' => $_POST['VendedorEmail'],
'TransacaoID' => $_POST['TransacaoID'],
'Referencia' => $_POST['Referencia'],
'Anotacao' => $_POST['Anotacao'],
'DataTransacao' => $DataHora,
'TipoPagamento' => $_POST['TipoPagamento'],
'StatusTransacao' => $_POST['StatusTransacao'],
'CliNome' => $_POST['CliNome'],
'CliEmail' => $_POST['CliEmail'],
'date_created' => 'now()');
if ((int)$_POST['ValorFrete'] > 0) {
$sql_data_array['Anotacao'] .= "\nFrete: ".$_POST['ValorFrete'];
}
zen_db_perform('temp_brpay', $sql_data_array);

$ids = explode(':',$_POST['Referencia']);
$order_id = $ids[1];

//Atualizar pedido conforme retorno do BrPay
switch($_POST['StatusTransacao']){
case 'Completo':
case 'Aprovado':
$sql_data_array = array('orders_status' => MODULE_PAYMENT_BRPAY_APPROVED_ORDER_STATUS_ID);
zen_db_perform(TABLE_ORDERS, $sql_data_array, 'update', "orders_id = '" . (int)$order_id . "'");
$this->debug_var ($_POST['Referencia'], "Pagamento aprovado já no retorno automatico: ".date("Y-m-d G:i:s"),true);
break;
case 'Em Análise':
case 'Aguardando Pagto':
$sql = "SELECT orders_status FROM ".TABLE_ORDERS." WHERE orders_id = " . (int)$order_id;
$rs_order = $db->Execute($sql);
$comments = "Autenticação BRPay: ". $_POST['TransacaoID'].
"\nAnotacao BRPay: ". $_POST['Anotacao'].
"\nTipo do Pagamento BRPay: ". $_POST['TipoPagamento'].
"\nStatus BRPay: ". $_POST['StatusTransacao'];

$sql_data_array = array('orders_id' => $order_id,
'orders_status_id' => $rs_order->fields['orders_status'],
'date_added' => 'now()',
'customer_notified' => '0',
'comments' => $comments);
zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
break;
default:
$email_order = 'Pedido feito no '. STORE_NAME . " com status de retorno desconhecido\n" .
'Cliente: '. $_POST['CliNome'] . " - " . $_POST['CliEmail'] . "\n" .
EMAIL_SEPARATOR . "\n" .
'Status do pagamento: '. $_POST['StatusTransacao'] . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n".
print_r($_SESSION,true);
zen_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, 'Pedido efetuado e pago no BRpay - email enviado para verificacao do funcionamento', $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
$this->debug_var($email_order, "email de suporte: ".date("Y-m-d G:i:s"),true);
} // switch

} else {

if (strcmp ($res, "FALSO") == 0) {
// LOG para investigacao manual
if (zen_not_null(MODULE_PAYMENT_BRPAY_DEBUG_EMAIL)) {
$email_body = '$_POST:' . "\n\n";
foreach ($_POST as $key => $value) {
$email_body .= $key . '=' . $value . "\n";
}
$email_body .= "\n" . '$_GET:' . "\n\n";
foreach ($_GET as $key => $value) {
$email_body .= $key . '=' . $value . "\n";
}

zen_mail('', MODULE_PAYMENT_BRPAY_DEBUG_EMAIL, 'Retorno automatico BRPay - Post Invalido ', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}
if ($txt = @fopen ('log/brpay-fake.log', 'a')) {
fwrite ($txt, "\n======================================\nVerificação de dados do retorno automático do BRPay falhou. \n Dados possivelmente falsificados: ".date("Y-m-d G:i:s"). "\n");
fwrite ($txt, print_r($_POST,true). "\n");
fclose($txt);
}
}
}

require('includes/application_bottom.php');

?>