<?php
class GSEmail extends GSModel {
var $from;
var $to;
var $bcc = "";
var $cc = "";
var $subject;
var $emailText = "";
var $userProfile;
var $DebugEmail = '';
var $EmailSentInfo;
static $ccNumbers = "";
function __construct() {
parent::__construct ();
$this->load->helper ( "file" );
//$this->load->config ( "GSConfig" );
$this->DebugEmail = $this->config->item ( "DebugMail" );
$this->load->library('email');
$this->email->initialize($this->GetEmailConfig());
}
function GetEmailConfig($isHtml=true){
$config['useragent'] = 'Datamoat';
$config['protocol'] = 'sendmail';
/*$config['mailpath'] = '/usr/sbin/sendmail';*/
$config['mailtype'] = $isHtml?'html':'text';
$config['charset'] = 'utf-8';
$config['wordwrap'] = FALSE;
return $config;
}
function SetPlanTextEmail(){
$this->email->initialize($this->GetEmailConfig(false));
}
function NewAccountEmail() {
$acc_password = substr ( $this->userProfile->PIN, - 5 );
$dear_name = $this->userProfile->FName . " " . $this->userProfile->LName;
$cc_number = $this->GetCallCenterNumber ();
$account_phone = $this->GetUserPhoneFull ();
$acc_country_name = $this->userProfile->Country;
$toll_free_rate = $this->GetTollFreeRate ();
$toll_free_access_number = $this->GetTollfreeNumber ();
$acc_promocode = $this->userProfile->promocode;
require_once (BASEPATH . "../EmailTemplate/new_account_success.php");
$access_number = DIDFormat ( $this->userProfile->NPA, $this->CountryInfo->countryPhoneFormat, 0, 1 );
$newAccounteEmail = new NewAccountSuccess ();
$promoRate = "$ 2.00";
$this->load->model ( "Database/Mpl_country" );
$this->Mpl_country = new Mpl_country ();
$this->Mpl_country->country_code ( $this->userProfile->country_code );
if ($this->Mpl_country->Select ( 'payment_currency_sign, amount_to_referrer, currency_small_unit, tollfree_rate' )) {
$promoRate = $this->Mpl_country->payment_currency_sign . $this->Mpl_country->amount_to_referrer;
$acc_cur_balance = $this->Mpl_country->payment_currency_sign . $acc_cur_balance;
$toll_free_rate = $this->Mpl_country->tollfree_rate." ".$this->Mpl_country->currency_small_unit;
}
$this->emailText = $newAccounteEmail->GetEmailText ( $dear_name, $cc_number, $account_phone, $acc_country_name, $acc_password, $acc_cur_balance, $toll_free_rate, $toll_free_access_number, $acc_promocode, $access_number, $promoRate );
$this->subject = "Your gTalk Pinless Calling Service Account Created Successfully";
return $this->SendEmail ();
}
function GetHeader($from = '', $replayTo = '', $bcc = '') {
if (empty ( $this->from )) {
$this->from = $this->config->item ( 'supportEmailAddress' );
}
if (empty ( $this->replayTo )) {
$this->replayTo = 'noreply@databank.com.bd';//'noreply@gtalk.us';
}
$headers = "From: " . $this->from . "\r\n";
if (! empty ( $this->DebugEmail )) {
$this->bcc = $this->DebugEmail;
$this->cc = $this->DebugEmail;
}
if (! empty ( $this->bcc ))
$headers .= "Bcc: " . $this->bcc . "\n";
if (! empty ( $this->cc )) {
$headers .= 'Cc: ' . $this->cc . "\r\n";
}
$x_mailer = "PHP/".phpversion();
$headers .= "Reply-To: " . $this->replayTo . "\r\n";
$headers .= 'X-Mailer: '.$x_mailer;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
return $headers;
}
function SendDBErrorMsg($heading = '', $msg = '') {
$this->load->config ( "GSConfig" );
$this->to ( $this->config->item ( "AdminEmail" ) );
$this->from ( $this->config->item ( supportEmailAddress ) );
$this->subject ( $heading );
$this->emailText ( $msg );
return $this->SendEmail ( true );
}
function SendEmail($isSignAdded = false) {
if (! $isSignAdded){
//$this->SetFooter ();
}
if (empty ( $this->to )) {
$this->AddError ( "To Field Empty!" );
return false;
}
if (empty ( $this->from )) {
$this->from = $this->config->item ( 'supportEmailAddress' );
}
if (! empty ( $this->DebugEmail )) {
//$this->to = $this->DebugEmail;
}
$this->email->clear();
$this->email->from($this->from, 'Datamoat');
$this->email->to($this->to);
$this->email->cc($this->cc);
$this->email->bcc($this->bcc);
$this->email->subject($this->subject);
$this->email->message($this->emailText);
//$this->email->send();
//if (! @mail ( $this->to, $this->subject, $this->emailText, $this->GetHeader () )) { //-fhabib@gtalk.us
if(!$this->email->send()){
//$this->AddSystemLog ( "Error on sending email: Subject:\"" . $this->subject . "\" Email is not sent" );
//$this->AddDebugMsg ( "Email sent failed:" . $this->subject, StatusError );
//$this->AddError("Email sent failed ".$this->subject,StatusError);
$this->AddError ( "Email Sending Failed!" );
return false;
} else {
$this->EmailSentInfo=$this->email->print_debugger();
$this->AddDebugMsg ($this->EmailSentInfo);
return true;
}
}
function SetFooter($isReturn = false) {
$ccNumber = $this->GetCallCenterNumber ();
$str = '<br/><font color="red"><b>
Customer Care<br />
Datamoat Service<br />
' . $ccNumber . '<br />
</b></font>';
$this->ReplaceTagByValue ( "Footer", $str );
if ($isReturn) {
return $str;
} else {
$this->emailText .= $str;
}
}
function GetAllGST(&$str) {
$Tags = array ();
preg_match_all ( "/{GS:.*?}/", $str, $Tags );
if (isset ( $Tags [0] ))
return $Tags [0];
else
return array ();
}
function ReplaceTagByValue($tag, $value) {
$tag = preg_replace ( "/ /", '', $tag );
$this->emailText = preg_replace ( "/{GS:.*?$tag.*?}/", $value, $this->emailText );
}
function GetTollfreeNumber() {
/*//Tollfreenumber (ServiceType ) collection
$rData ['tollFreeNumbers'] = null;
$serviceType = new Mservice_type ();
$serviceType->web_view ( 'Y' );
$serviceType->active ( 'Y' );
$serviceType->tollfree ( 'Y' );
$serviceType->country_code ( $this->userProfile->country_code );
$tollFreeNumbers = $serviceType->SelectAll ( 'DID_full' );*/
}
function GetUserPhoneFull() {
return DIDFormat ( $this->userProfile->account_phone_full, $this->CountryInfo->countryPhoneFormat, strlen ( $this->CountryInfo->countryPhoneCode ) );
}
function GetTollFreeRate() {
return 0;
}
function GetCallCenterNumber( $countryCode='', $phoneFormat='', $phoneCode='') {
//Call Center Number (ServiceType ) collection
/*
$userCCode = "US";
$userPFormat = "(999) 999-9999";
$userPCode = "1";
$userType = $this->session->GetCurrentUserType();
if ($userType == "CC" || $userType == "AD"){
$userCCode = $countryCode;
$userPFormat = $phoneFormat;
$userPCode = $phoneCode;
}else {
$userCCode = $this->CountryInfo->countryCode;
$userPFormat = $this->CountryInfo->countryPhoneFormat;
$userPCode = $this->CountryInfo->countryPhoneCode;
}
if (empty ( GSEmail::$ccNumbers )) {
$this->load->Model ( "Database/Mservice_type" );
$serviceType = new Mservice_type ();
$serviceType->web_view ( 'Y' );
$serviceType->active ( 'Y' );
$serviceType->Type ( "CC" );
$serviceType->country_code ( $userCCode );
$ccNumbers = $serviceType->SelectAll ( 'DID_full' );
$str = "";
if (!empty($ccNumbers)){
foreach ( $ccNumbers as $st ) {
$str .= DIDFormat ( $st->DID_full, $userPFormat, strlen ( $userPCode ) ) . ", ";
}
}
GSEmail::$ccNumbers=rtrim ( $str, ", " );
}
return GSEmail::$ccNumbers;
*/
return "880 171 7567386";
}
/**
* Enter description here ...
* @param FileName $fileName
* @return Ambigous <boolean, string>
*/
private function LoadEmailTemplate($fileName) {
if (! (endsWith ( $fileName, ".html" ) || endsWith ( $fileName, ".htm" ))) {
$fileName .= ".html";
}
return read_file ( BASEPATH . "../EmailTemplate/" . $fileName );
}
///function
}