Index: admin_templates/languages/email_message_list.tpl
===================================================================
--- admin_templates/languages/email_message_list.tpl (revision 15437)
+++ admin_templates/languages/email_message_list.tpl (working copy)
@@ -50,6 +50,12 @@
open_popup('emailevents', 'OnExportEmailEvents', 'regional/languages_export');
+
+
+ submit_event('emailevents', 'OnSend');
+
+
+
a_toolbar.AddButton( new ToolBarSeparator('sep2') );
@@ -82,6 +88,6 @@
\ No newline at end of file
Index: kernel/utility/email.php
===================================================================
--- kernel/utility/email.php (revision 15437)
+++ kernel/utility/email.php (working copy)
@@ -141,7 +141,8 @@
throw new InvalidArgumentException('Invalid e-mail event type');
}
- $this->emailEvent = $this->Application->recallObject('emailevents', null, Array ('skip_autoload' => true));
+ // use "-item" special prevent error, when e-mail sent out from e-mail events list
+ $this->emailEvent = $this->Application->recallObject('emailevents.-item', null, Array ('skip_autoload' => true));
if ( !$this->emailEvent->isLoaded() || !$this->_sameEvent($name, $type) ) {
// get event parameters by name & type
@@ -744,7 +745,7 @@
$design_templates[$design_key] = $design_template;
}
- return $this->_parseText(str_replace('$body', $text, $design_templates[$design_key]));
+ return $this->_parseText(str_replace('$body', $text, $design_templates[$design_key]), $is_html);
}
/**
@@ -768,7 +769,7 @@
}
if ( isset($this->params['use_custom_design']) && $this->params['use_custom_design'] ) {
- $message_body = $this->_parseText($message_body);
+ $message_body = $this->_parseText($message_body, $is_html);
}
else {
$message_body = $this->_applyMessageDesign($message_body, $is_html);
@@ -781,10 +782,11 @@
* Parse message template and return headers (as array) and message body part
*
* @param string $text
+ * @param bool $is_html
* @return string
* @access protected
*/
- protected function _parseText($text)
+ protected function _parseText($text, $is_html = true)
{
$text = $this->_substituteReplacementTags($text);
@@ -796,15 +798,15 @@
$this->Application->InitParser();
$parser_params = $this->Application->Parser->Params; // backup parser params
- $this->Application->Parser->SetParams( array_merge($parser_params, $this->params) );
+ $this->Application->Parser->SetParams($this->params);
- $text = $this->Application->Parser->Parse($text, 'email_template');
+ $text = $this->Application->Parser->Parse($this->_normalizeLineEndings($text), 'email_template');
$this->Application->Parser->SetParams($parser_params); // restore parser params
$category_helper = $this->Application->recallObject('CategoryHelper');
/* @var $category_helper CategoryHelper */
- return $category_helper->replacePageIds($this->_normalizeLineEndings($text));
+ return $category_helper->replacePageIds($is_html ? $this->_removeTrailingLineEndings($text) : $text);
}
/**
@@ -834,7 +836,7 @@
}
/**
- * Normalizes line endings in given text
+ * Convert Unix/Windows/Mac line ending into Unix line endings
*
* @param string $text
* @return string
@@ -842,10 +844,18 @@
*/
protected function _normalizeLineEndings($text)
{
- // remove trailing line endings
- $text = preg_replace('/(\n|\r)+/', "\\1", $text);
-
- // convert Unix/Windows/Mac line ending into Unix line endings
return str_replace(Array ("\r\n", "\r"), "\n", $text);
}
+
+ /**
+ * Remove trailing line endings
+ *
+ * @param $text
+ * @return string
+ * @access protected
+ */
+ protected function _removeTrailingLineEndings($text)
+ {
+ return preg_replace('/(\n|\r)+/', "\\1", $text);
+ }
}
\ No newline at end of file
Index: units/email_events/email_events_config.php
===================================================================
--- units/email_events/email_events_config.php (revision 15437)
+++ units/email_events/email_events_config.php (working copy)
@@ -45,7 +45,7 @@
// for separate grid with email editing
'email_message_list' => Array (
'prefixes' => Array ('emailevents_List'), 'format' => "!la_title_EmailMessages!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'frontend_mail', 'export', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'frontend_mail', 'export', 'process', 'view', 'dbl-click'),
),
'email_message_edit' => Array (
Index: units/email_events/email_events_event_handler.php
===================================================================
--- units/email_events/email_events_event_handler.php (revision 15465)
+++ units/email_events/email_events_event_handler.php (working copy)
@@ -42,6 +42,7 @@
'OnMassDelete' => Array ('self' => 'debug'),
'OnMassApprove' => Array ('self' => 'debug'),
'OnMassDecline' => Array ('self' => 'debug'),
+ 'OnSend' => Array ('self' => 'debug'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -193,10 +194,8 @@
$items_info = $this->Application->GetVar('u');
if ( $items_info ) {
- $user_id = array_shift(array_keys($items_info));
+ list ($user_id, ) = each($items_info);
- $selected_ids = $this->getSelectedIDs($event, true);
-
$ids = $this->Application->RecallVar($event->getPrefixSpecial() . '_selected_ids');
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
$table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
@@ -726,4 +725,32 @@
$temp_handler->DeleteItems('system-event-subscription', '', $ids);
}
+
+ /**
+ * Sends selected e-mail event
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnSend(kEvent $event)
+ {
+ $object = $event->getObject(Array ('skip_autoload' => true));
+ /* @var $object kDBItem */
+
+ $ids = $this->StoreSelectedIDs($event);
+
+ foreach ($ids as $id) {
+ $object->Load($id);
+
+ if ( $object->GetDBField('Type') == EmailEvent::EVENT_TYPE_ADMIN ) {
+ $this->Application->EmailEventAdmin($object->GetDBField('Event'));
+ }
+ else {
+ $this->Application->EmailEventUser($object->GetDBField('Event'));
+ }
+ }
+
+ $this->clearSelectedIDs($event);
+ }
}
\ No newline at end of file