Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Mon, Feb 3, 12:58 AM

in-portal

Index: trunk/kernel/units/email_events/email_events_event_handler.php
===================================================================
--- trunk/kernel/units/email_events/email_events_event_handler.php (revision 1731)
+++ trunk/kernel/units/email_events/email_events_event_handler.php (revision 1732)
@@ -1,196 +1,194 @@
<?php
class EmailEventsEventsHandler extends InpDBEventHandler
{
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
if($event->Special == 'module')
{
$object =& $event->getObject();
$object->addFilter('module_filter', '%1$s.Module = \'In-Commerce\'');
}
}
/**
* Sets status Front-End Only to selected email events
*
* @param kEvent $event
*/
function OnFrontOnly(&$event)
{
$this->StoreSelectedIDs($event);
$ids = $this->getSelectedIDs($event);
$ids = implode(',', $ids);
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'UPDATE '.$table.' SET Enabled = 2 WHERE EventId IN ('.$ids.')';
$this->Conn->Query($sql);
}
/**
* Sets selected user to email events selected
*
* @param kEvent $event
*/
function OnSelectUser(&$event)
{
$user_name = $this->Application->GetVar( $event->getPrefixSpecial(true).'_PopupSelectedUser' );
if( strlen($user_name) > 0 )
{
$this->StoreSelectedIDs($event);
$ids = $this->getSelectedIDs($event);
$ids = implode(',', $ids);
$user_id = $this->Conn->GetOne('SELECT PortalUserId FROM '.TABLE_PREFIX.'PortalUser WHERE Login = '.$this->Conn->qstr($user_name) );
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'UPDATE '.$table.' SET FromUserId = '.$user_id.' WHERE EventId IN ('.$ids.')';
$this->Conn->Query($sql);
}
}
/**
* Raised when email message shoul be sent
*
* @param kEvent $event
*/
function OnEmailEvent(&$event){
$email_event = $event->getEventParam('EmailEventName');
$to_user_id = $event->getEventParam('EmailEventToUserId');
$email_event_type = $event->getEventParam('EmailEventType');
$this->Application->setUnitOption('emailmessages', 'AutoLoad', false);
$message_object = &$this->Application->recallObject('emailmessages');
$event_table = $this->Application->getUnitOption('emailevents', 'TableName');
$event_object = &$event->getObject();
$event_object->Load(array('Event'=>$email_event, 'Type'=>$email_event_type));
$event_id = $event_object->GetDBField('EventId');
$from_user_id = $event_object->GetDBField('FromUserId');
$type = $event_object->GetDBField('Type');
$enabled = $event_object->GetDBField('Enabled');
$direct_send_params = $event->getEventParam('DirectSendParams');
if ($enabled == 0) return; // disabled event
if ($enabled == 2 && defined("ADMIN")) return; // event only for front-end
if ($type == 1){
// For type "Admin" recipient is a user from field FromUserId which means From/To user in Email events list
$to_user_id = $from_user_id;
$from_user_id = -1;
}
if (!($to_user_id > 0) && !$direct_send_params){
// if we can not determine recepient we will not send email
return;
}
//Parse Message Template
$message_object->Load(array('EventId' => $event_id, 'LanguageId' => $this->Application->GetVar('m_lang')));
$message_type = $message_object->GetDBField('MessageType');
$message_template = $message_object->GetDBField('Template');
-
- $this->Application->InitParser();
- $template =& $this->Application->makeClass('Template');
- $template->SetBody($message_template);
-
- $template_object = &$this->Application->recallObject('TemplatesCache');
- $template_object->SetTemplate('EmailTemplate', $template);
-
$email_object = &$this->Application->recallObject('kEmailMessage');
$old_autoload = $this->Application->getUnitOption('u', 'AutoLoad');
$this->Application->setUnitOption('u', 'AutoLoad', false);
$from_user_object = &$this->Application->recallObject('u.-item');
$from_user_object->Load($from_user_id);
// here if we don't have from_user loaded, it takes a default user from config values
$from_user_email = $from_user_object->GetDBField('Email')?$from_user_object->GetDBField('Email'):$this->Application->ConfigValue('Smtp_AdminMailFrom');
$from_user_name = trim($from_user_object->GetDBField('FirstName').' '.$from_user_object->GetDBField('LastName'));
$to_user_object = &$this->Application->recallObject('u.-item');
$to_user_object->Load($to_user_id);
$to_user_email = $to_user_object->GetDBField('Email');
$to_user_name = trim($to_user_object->GetDBField('FirstName').' '.$to_user_object->GetDBField('LastName'));
$this->Application->setUnitOption('u', 'AutoLoad', $old_autoload);
if($direct_send_params){
$to_user_email = ($direct_send_params['to_email']?$direct_send_params['to_email']:$to_user_email);
$to_user_name = ($direct_send_params['to_name']?$direct_send_params['to_name']:$to_user_name);
$from_user_email = ($direct_send_params['from_email']?$direct_send_params['from_email']:$from_user_email);
$from_user_name = ($direct_send_params['from_name']?$direct_send_params['from_name']:$from_user_name);
$message_body_additional = $direct_send_params['message'];
}
-
- $params = array_merge( array('name'=>'EmailTemplate', 'message_text'=>$message_body_additional), $direct_send_params );
- $message_template = $this->Application->ParseBlock($params);
-
+
+
+ $this->Application->makeClass('Template');
+ $this->Application->InitParser();
+ $parser_params = $this->Application->Parser->Params;
+ $direct_send_params['message_text'] = $message_body_additional;
+ $this->Application->Parser->Params = array_merge_recursive2($this->Application->Parser->Params, $direct_send_params);
+ $message_template = $this->Application->Parser->Parse($message_template, '', 0);
+ $this->Application->Parser->Params = $parser_params;
+
$message_template = str_replace("\r", "", $message_template);
list($message_headers, $message_body) = explode("\n\n", $message_template, 2);
$email_object->setFrom($from_user_email, $from_user_name);
$email_object->setTo($to_user_email, $to_user_name);
$email_object->setSubject('Mail message');
$email_object->setHeaders($message_headers);
if ($message_type == 'html'){
$email_object->setHTMLBody($message_body);
}
else {
$email_object->setTextBody($message_body);
}
$smtp_object = &$this->Application->recallObject('kSmtpClient');
$smtp_server = $this->Application->ConfigValue('Smtp_Server');
$smtp_port = $this->Application->ConfigValue('Smtp_Port');
$smtp_authenticate = $this->Application->ConfigValue('Smtp_Authenticate');
if ($smtp_authenticate){
$smtp_user = $this->Application->ConfigValue('Smtp_User');
$smtp_pass = $this->Application->ConfigValue('Smtp_Pass');
}else{
$smtp_user = '';
$smtp_pass = '';
}
if ($smtp_server){
if ($email_object->sendSMTP($smtp_object, $smtp_server, $smtp_user, $smtp_pass, $smtp_authenticate)){
$event->status=erSUCCESS;
}
else {
$event->status=erFAIL;
}
}else{
if($email_object->send()){
$event->status=erSUCCESS;
}
else {
$event->status=erFAIL;
}
}
return $event;
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/email_events/email_events_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/core/units/email_events/email_events_event_handler.php
===================================================================
--- trunk/core/units/email_events/email_events_event_handler.php (revision 1731)
+++ trunk/core/units/email_events/email_events_event_handler.php (revision 1732)
@@ -1,196 +1,194 @@
<?php
class EmailEventsEventsHandler extends InpDBEventHandler
{
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function SetCustomQuery(&$event)
{
if($event->Special == 'module')
{
$object =& $event->getObject();
$object->addFilter('module_filter', '%1$s.Module = \'In-Commerce\'');
}
}
/**
* Sets status Front-End Only to selected email events
*
* @param kEvent $event
*/
function OnFrontOnly(&$event)
{
$this->StoreSelectedIDs($event);
$ids = $this->getSelectedIDs($event);
$ids = implode(',', $ids);
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'UPDATE '.$table.' SET Enabled = 2 WHERE EventId IN ('.$ids.')';
$this->Conn->Query($sql);
}
/**
* Sets selected user to email events selected
*
* @param kEvent $event
*/
function OnSelectUser(&$event)
{
$user_name = $this->Application->GetVar( $event->getPrefixSpecial(true).'_PopupSelectedUser' );
if( strlen($user_name) > 0 )
{
$this->StoreSelectedIDs($event);
$ids = $this->getSelectedIDs($event);
$ids = implode(',', $ids);
$user_id = $this->Conn->GetOne('SELECT PortalUserId FROM '.TABLE_PREFIX.'PortalUser WHERE Login = '.$this->Conn->qstr($user_name) );
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$sql = 'UPDATE '.$table.' SET FromUserId = '.$user_id.' WHERE EventId IN ('.$ids.')';
$this->Conn->Query($sql);
}
}
/**
* Raised when email message shoul be sent
*
* @param kEvent $event
*/
function OnEmailEvent(&$event){
$email_event = $event->getEventParam('EmailEventName');
$to_user_id = $event->getEventParam('EmailEventToUserId');
$email_event_type = $event->getEventParam('EmailEventType');
$this->Application->setUnitOption('emailmessages', 'AutoLoad', false);
$message_object = &$this->Application->recallObject('emailmessages');
$event_table = $this->Application->getUnitOption('emailevents', 'TableName');
$event_object = &$event->getObject();
$event_object->Load(array('Event'=>$email_event, 'Type'=>$email_event_type));
$event_id = $event_object->GetDBField('EventId');
$from_user_id = $event_object->GetDBField('FromUserId');
$type = $event_object->GetDBField('Type');
$enabled = $event_object->GetDBField('Enabled');
$direct_send_params = $event->getEventParam('DirectSendParams');
if ($enabled == 0) return; // disabled event
if ($enabled == 2 && defined("ADMIN")) return; // event only for front-end
if ($type == 1){
// For type "Admin" recipient is a user from field FromUserId which means From/To user in Email events list
$to_user_id = $from_user_id;
$from_user_id = -1;
}
if (!($to_user_id > 0) && !$direct_send_params){
// if we can not determine recepient we will not send email
return;
}
//Parse Message Template
$message_object->Load(array('EventId' => $event_id, 'LanguageId' => $this->Application->GetVar('m_lang')));
$message_type = $message_object->GetDBField('MessageType');
$message_template = $message_object->GetDBField('Template');
-
- $this->Application->InitParser();
- $template =& $this->Application->makeClass('Template');
- $template->SetBody($message_template);
-
- $template_object = &$this->Application->recallObject('TemplatesCache');
- $template_object->SetTemplate('EmailTemplate', $template);
-
$email_object = &$this->Application->recallObject('kEmailMessage');
$old_autoload = $this->Application->getUnitOption('u', 'AutoLoad');
$this->Application->setUnitOption('u', 'AutoLoad', false);
$from_user_object = &$this->Application->recallObject('u.-item');
$from_user_object->Load($from_user_id);
// here if we don't have from_user loaded, it takes a default user from config values
$from_user_email = $from_user_object->GetDBField('Email')?$from_user_object->GetDBField('Email'):$this->Application->ConfigValue('Smtp_AdminMailFrom');
$from_user_name = trim($from_user_object->GetDBField('FirstName').' '.$from_user_object->GetDBField('LastName'));
$to_user_object = &$this->Application->recallObject('u.-item');
$to_user_object->Load($to_user_id);
$to_user_email = $to_user_object->GetDBField('Email');
$to_user_name = trim($to_user_object->GetDBField('FirstName').' '.$to_user_object->GetDBField('LastName'));
$this->Application->setUnitOption('u', 'AutoLoad', $old_autoload);
if($direct_send_params){
$to_user_email = ($direct_send_params['to_email']?$direct_send_params['to_email']:$to_user_email);
$to_user_name = ($direct_send_params['to_name']?$direct_send_params['to_name']:$to_user_name);
$from_user_email = ($direct_send_params['from_email']?$direct_send_params['from_email']:$from_user_email);
$from_user_name = ($direct_send_params['from_name']?$direct_send_params['from_name']:$from_user_name);
$message_body_additional = $direct_send_params['message'];
}
-
- $params = array_merge( array('name'=>'EmailTemplate', 'message_text'=>$message_body_additional), $direct_send_params );
- $message_template = $this->Application->ParseBlock($params);
-
+
+
+ $this->Application->makeClass('Template');
+ $this->Application->InitParser();
+ $parser_params = $this->Application->Parser->Params;
+ $direct_send_params['message_text'] = $message_body_additional;
+ $this->Application->Parser->Params = array_merge_recursive2($this->Application->Parser->Params, $direct_send_params);
+ $message_template = $this->Application->Parser->Parse($message_template, '', 0);
+ $this->Application->Parser->Params = $parser_params;
+
$message_template = str_replace("\r", "", $message_template);
list($message_headers, $message_body) = explode("\n\n", $message_template, 2);
$email_object->setFrom($from_user_email, $from_user_name);
$email_object->setTo($to_user_email, $to_user_name);
$email_object->setSubject('Mail message');
$email_object->setHeaders($message_headers);
if ($message_type == 'html'){
$email_object->setHTMLBody($message_body);
}
else {
$email_object->setTextBody($message_body);
}
$smtp_object = &$this->Application->recallObject('kSmtpClient');
$smtp_server = $this->Application->ConfigValue('Smtp_Server');
$smtp_port = $this->Application->ConfigValue('Smtp_Port');
$smtp_authenticate = $this->Application->ConfigValue('Smtp_Authenticate');
if ($smtp_authenticate){
$smtp_user = $this->Application->ConfigValue('Smtp_User');
$smtp_pass = $this->Application->ConfigValue('Smtp_Pass');
}else{
$smtp_user = '';
$smtp_pass = '';
}
if ($smtp_server){
if ($email_object->sendSMTP($smtp_object, $smtp_server, $smtp_user, $smtp_pass, $smtp_authenticate)){
$event->status=erSUCCESS;
}
else {
$event->status=erFAIL;
}
}else{
if($email_object->send()){
$event->status=erSUCCESS;
}
else {
$event->status=erFAIL;
}
}
return $event;
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/email_events/email_events_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property

Event Timeline