106 lines
3.7 KiB
PHP
106 lines
3.7 KiB
PHP
<?php
|
|
class ClassMail extends ClassConfig {
|
|
public function __construct(){}
|
|
public function __destruct(){}
|
|
|
|
public function getMessage($message_code, $lang_code, $set_data){
|
|
$this->_messageCode = $message_code;
|
|
$this->_langCode = $lang_code;
|
|
$this->_setData = $set_data;
|
|
$oTrans = new ClassTranslation();
|
|
|
|
$message = $oTrans->getTranslation($this->_messageCode, $this->_langCode);
|
|
$replacement_regex = '/\[data\]/';
|
|
|
|
foreach($this->_setData as $k=>$v){
|
|
$message = preg_replace($replacement_regex, $this->_setData[$k], $message, 1);
|
|
}
|
|
|
|
return $message;
|
|
}
|
|
|
|
public function sendMail($sender_email, $receiver_email, $subject, $content){
|
|
$this->_senderEmail = $sender_email;
|
|
$this->_receiverEmail = $receiver_email;
|
|
$this->_subject = $subject;
|
|
$this->_content = $content;
|
|
|
|
$header = "MIME-Version: 1.0\r\n";
|
|
$header .= "Content-type: text/html; charset=utf-8-1\r\n";
|
|
$header .= "From: ".$this->_senderEmail."\r\n";
|
|
|
|
$res = array();
|
|
if(mail($this->_receiverEmail,
|
|
$this->_subject,
|
|
$this->_content, $header)){
|
|
$res['state'] = 'success';
|
|
} else{
|
|
$res['state'] = 'failed';
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
//TODO alert seller by mail
|
|
public function alertSellerByEmailForMatch($portfolio_sell_id){
|
|
$this->_portfolioSellId = $portfolio_sell_id;
|
|
$oPDOLink = ClassConfig::databaseConnect();
|
|
$sql = "
|
|
SELECT cu.email, (SELECT code FROM core_lang WHERE id=cu.core_lang_id LIMIT 1) AS lang_code
|
|
FROM portfolio_sell sps
|
|
INNER JOIN user_user cu
|
|
ON sps.user_id=cu.id
|
|
WHERE sps.id=:id
|
|
LIMIT 1
|
|
";
|
|
$execSQL = $oPDOLink->prepare($sql);
|
|
$execSQL->execute(array(
|
|
':id'=>$this->_portfolioSellId
|
|
));
|
|
$sps = $execSQL->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$this->sendMail(
|
|
"info@skills-trading.com",
|
|
$sps['email'],
|
|
ClassTranslation::getTranslation('email_subjectMatchForSeller', $sps['lang_code']), //$_SESSION['config']['default_lang_code']
|
|
ClassMail::getMessage('email_contentMatchForSeller',
|
|
$sps['lang_code'], //$_SESSION['config']['default_lang_code'],
|
|
array("David"
|
|
)
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
//TODO alert buyer by mail
|
|
public function alertBuyerByEmailForMatch($portfolio_buy_id){
|
|
$this->_portfolioBuyId = $portfolio_buy_id;
|
|
$oPDOLink = ClassConfig::databaseConnect();
|
|
$sql = "
|
|
SELECT cu.email, (SELECT code FROM core_lang WHERE id=cu.core_lang_id LIMIT 1) AS lang_code
|
|
FROM portfolio_buy spb
|
|
INNER JOIN user_user cu
|
|
ON spb.user_id=cu.id
|
|
WHERE spb.id=:id
|
|
LIMIT 1
|
|
";
|
|
$execSQL = $oPDOLink->prepare($sql);
|
|
$execSQL->execute(array(
|
|
':id'=>$this->_portfolioBuyId
|
|
));
|
|
$spb = $execSQL->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$this->sendMail(
|
|
"info@skills-trading.com",
|
|
$spb['email'],
|
|
ClassTranslation::getTranslation('email_subjectMatchForBuyer', $spb['lang_code']), //$_SESSION['config']['default_lang_code']
|
|
ClassMail::getMessage('email_contentMatchForBuyer',
|
|
$spb['lang_code'], //$_SESSION['config']['default_lang_code'],
|
|
array("David"
|
|
)
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
}
|