Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Fri, Jun 20, 11:41 AM

in-portal

Index: branches/RC/core/units/email_messages/email_messages_event_handler.php
===================================================================
--- branches/RC/core/units/email_messages/email_messages_event_handler.php (revision 10193)
+++ branches/RC/core/units/email_messages/email_messages_event_handler.php (revision 10194)
@@ -1,372 +1,387 @@
<?php
class EmailMessagesEventHandler extends kDBEventHandler
{
/**
* Replace id passed with id of email message
*
* @param kEvent $event
*/
function getPassedID(&$event)
{
$parent = parent::getPassedID($event);
if ($parent) return $parent;
$email_event_id = (int)$this->getEmailEventId();
$object =& $event->getObject();
$parent_info = $object->getLinkedInfo();
$sql = 'SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE ('.$parent_info['ForeignKey'].' = '.$parent_info['ParentId'].') AND (EventId = '.$email_event_id.')';
$id = (int)$this->Conn->GetOne($sql);
if(!$id)
{
$object->SetDBField('EventId', $email_event_id);
$object->SetDBField('Headers', $this->Application->ConfigValue('Smtp_DefaultHeaders') );
}
return $id;
}
function getEmailEventId()
{
return parent::getPassedID( new kEvent('emailevents:OnDummy') );
}
/**
* 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();
$module = $this->Application->GetVar('module');
$object->addFilter('module_filter', 'Module = '.$this->Conn->qstr($module));
}
}
/**
* If loading empty item, then set parent id
*
* @param kEvent $event
*/
function OnBeforeItemLoad(&$event)
{
- if( !$event->getEventParam('id') )
- {
+ if (!$event->getEventParam('id')) {
$this->OnNew($event);
+
$event->status = erFATAL;
}
}
/**
+ * Sets event id
+ *
+ * @param kEvent $event
+ */
+ function OnNew(&$event)
+ {
+ parent::OnNew($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $object->SetDBField('EventId', $this->getEmailEventId());
+ }
+
+ /**
* Parse message template (split into header, subject & body)
*
* @param kEvent $event
*/
function OnAfterItemLoad(&$event)
{
$object =& $event->getObject();
$lines = explode("\n", $object->GetDBField('Template') );
$headers = Array();
foreach($lines as $line)
{
if( strlen(trim($line)) == 0 || ($line == '.') ) break;
$parts = explode(':', $line, 2);
if(strtolower($parts[0]) == 'subject')
{
$object->SetDBField('Subject', trim($parts[1]) );
}
else
{
$headers[] = $line;
}
}
$object->SetDBField('Headers', implode("\n", $headers) );
$message_body = '';
while( (list($line_id,$line) = each($lines)) )
{
$message_body .= $line;
}
$object->SetDBField('Body', $message_body);
}
/**
* Merge body+subject+headers into message template
*
* @param kEvent $event
*/
function OnBeforeItemUpdate(&$event)
{
$this->parseVirtualFields($event);
}
/**
* Merge body+subject+headers into message template
*
* @param kEvent $event
*/
function OnBeforeItemCreate(&$event)
{
$this->parseVirtualFields($event);
}
/**
* Merge body+subject+headers into message template
*
* @param kEvent $event
*/
function parseVirtualFields(&$event)
{
$object =& $event->getObject();
if( $object->GetDBField('Headers') || $object->GetDBField('Subject') || $object->GetDBField('Body') )
{
$ret = $object->GetDBField('Headers');
if($ret) $ret .= "\n";
$ret = $this->removeTrailingCRLF($ret);
$ret .= 'Subject: '.$object->GetDBField('Subject')."\n\n";
$ret .= $object->GetDBField('Body');
$object->SetDBField('Template', $ret);
}
}
/**
* Remove trailing CR/LF chars from string
*
* @param string $string
* @return string
*/
function removeTrailingCRLF($string)
{
return preg_replace('/(\n|\r)+/',"\\1",$string);
}
/**
* Prepares selected user(-s) or group(-s) for message sending
*
* @param kEvent $event
*/
function OnPrepareMassRecipients(&$event)
{
$object =& $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
$object->Clear(0);
$event->redirect = false;
$this->Application->RemoveVar('recipient_ids');
$this->Application->RemoveVar('recipient_type');
$this->saveMassRecipients('u');
$this->saveMassRecipients('g', 'total');
}
function saveMassRecipients($prefix, $special = '')
{
$recipients = $this->Application->GetVar(rtrim($prefix.'_'.$special, '_'));
if ($recipients) {
$this->Application->StoreVar('recipient_ids', implode(',', array_keys($recipients)));
$this->Application->StoreVar('recipient_type', $prefix);
}
}
/**
* Sends mass mail
*
* @param kEvent $event
*/
function OnMassMail(&$event)
{
$object =& $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
$object->setRequired('MassSubject', true);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if ($items_info) {
list($id, $field_values) = each($items_info);
$object->SetFieldsFromHash($field_values);
}
if (!$object->Validate()) {
$event->redirect = false;
$event->status = erFAIL;
$object->setID($id);
return ;
}
$fields_hash = $object->GetFieldValues();
list ($fields_hash['FromEmail'], $fields_hash['FromName']) = $this->getSenderData();
if ($fields_hash['MassAttachment']) {
$field_options = $object->GetFieldOptions('MassAttachment');
$fields_hash['MassAttachment'] = $field_options['upload_dir'].$fields_hash['MassAttachment'];
}
$this->Application->RemoveVar('email_prepare_progress');
$this->Application->StoreVar('email_prepare_fields', serialize($fields_hash));
$event->redirect = 'emails/prepare_queue';
}
/**
* Generates email queue using progress bar
*
* @param kEvent $event
*/
function OnPrepareEmailQueue(&$event)
{
$prepare_count = $this->Application->ConfigValue('Smtp_ProcessEmailsPerStep');
if ($prepare_count === false) {
// 10 recipients per script run (if none defined in config)
$prepare_count = 10;
}
$email_prepare_progress = $this->Application->RecallVar('email_prepare_progress');
if ($email_prepare_progress === false) {
$emails_prepared = 0;
$total_emails = $this->getRecipientEmails(true);
$this->Application->StoreVar('email_prepare_progress', $emails_prepared.':'.$total_emails);
}
else {
list ($emails_prepared, $total_emails) = explode(':', $email_prepare_progress);
}
$recipient_emails = $this->getRecipientEmails(false, $emails_prepared.','.$prepare_count);
$recipient_email_count = count($recipient_emails);
if (!$recipient_email_count) {
// no recipients left to prepare
$this->finalizeQueuePreparing($fields_hash['MassAttachment']);
}
$fields_hash = unserialize($this->Application->RecallVar('email_prepare_fields'));
$esender =& $this->Application->recallObject('EmailSender');
/* @var $esender kEmailSendingHelper */
// 1. set headers same for all emails
$esender->SetFrom($fields_hash['FromEmail'], $fields_hash['FromName']);
$esender->SetSubject($fields_hash['MassSubject']);
$esender->SetBody($fields_hash['MassHtmlMessage'], $fields_hash['MassTextMessage']);
// 2. add attachment if any
if ($fields_hash['MassAttachment']) {
$esender->AddAttachment(FULL_PATH.$fields_hash['MassAttachment']);
}
foreach ($recipient_emails as $recipient_email) {
// 3. set recipient specific fields
$esender->SetEncodedEmailHeader('To', $recipient_email, $recipient_email);
$esender->Deliver(null, false, false);
// 4. write to log
$log_fields_hash = Array (
'fromuser' => $fields_hash['FromName'],
'addressto' => $recipient_email,
'subject' => $fields_hash['MassSubject'],
'timestamp' => adodb_mktime(),
'event' => '',
);
$this->Conn->doInsert($log_fields_hash, TABLE_PREFIX.'EmailLog');
}
$emails_prepared += $recipient_email_count;
if ($emails_prepared >= $total_emails) {
$this->finalizeQueuePreparing($fields_hash['MassAttachment']);
}
$this->Application->StoreVar('email_prepare_progress', $emails_prepared.':'.$total_emails);
$event->status = erSTOP;
echo ($emails_prepared / $total_emails) * 100;
}
function finalizeQueuePreparing($attachment_file = null)
{
// variables from users/groups grid
$this->Application->RemoveVar('recipient_ids');
$this->Application->RemoveVar('recipient_type');
if ($attachment_file) {
unlink(FULL_PATH.$attachment_file);
}
// variables from email preparing process
// $this->Application->RemoveVar('email_prepare_progress');
// $this->Application->RemoveVar('email_prepare_fields');
// variables from email delivering process (not yet executed)
$this->Application->RemoveVar('email_queue_progress');
$this->Application->Redirect($this->Application->GetVar('finish_template'));
}
function getRecipientEmails($for_counting = false, $limit = null)
{
$recipient_type = $this->Application->RecallVar('recipient_type');
$recipient_ids = $this->Application->RecallVar('recipient_ids');
if (!$recipient_ids) {
return $for_counting ? 0 : Array ();
}
if ($recipient_type == 'u') {
$sql = 'SELECT '.($for_counting ? 'COUNT(*)' : 'Email').'
FROM '.TABLE_PREFIX.'PortalUser
WHERE PortalUserId IN ('.$recipient_ids.')';
}
else {
$sql = 'SELECT '.($for_counting ? 'COUNT(*)' : 'u.Email').'
FROM '.TABLE_PREFIX.'UserGroup ug
LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON ug.PortalUserId = u.PortalUserId
WHERE ug.GroupId IN ('.$recipient_ids.')';
}
if ($for_counting) {
return $this->Conn->GetOne($sql);
}
if (isset($limit)) {
$sql .= ' LIMIT '.$limit;
}
return $this->Conn->GetCol($sql);
}
/**
* Returns mass mail sender name & email
*
* @return Array
*/
function getSenderData()
{
$user =& $this->Application->recallObject('u.current');
/* @var $user UsersItem */
if ($user->GetID() > 0) {
$email_address = $user->GetDBField('Email');
$name = $user->GetDBField('FirstName').' '.$user->GetDBField('LastName');
}
else {
$email_address = $this->Application->ConfigValue('Smtp_AdminMailFrom');
$name = strip_tags( $this->Application->ConfigValue('Site_Name') );
}
return Array ($email_address, $name);
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/units/email_messages/email_messages_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6.2.3
\ No newline at end of property
+1.6.2.4
\ No newline at end of property
Index: branches/RC/core/units/email_messages/email_messages_config.php
===================================================================
--- branches/RC/core/units/email_messages/email_messages_config.php (revision 10193)
+++ branches/RC/core/units/email_messages/email_messages_config.php (revision 10194)
@@ -1,87 +1,87 @@
<?php
$config = Array (
'Prefix' => 'emailmessages',
'ItemClass' => Array('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
'ListClass' => Array('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
'EventHandlerClass' => Array('class' => 'EmailMessagesEventHandler', 'file' => 'email_messages_event_handler.php', 'build_event' => 'OnBuild'),
'TagProcessorClass' => Array('class' => 'EmailMessageTagProcessor', 'file' => 'email_message_tp.php', 'build_event' => 'OnBuild'),
'AutoLoad' => true,
'QueryString' => Array (
1 => 'id',
2 => 'page',
3 => 'event',
4 => 'mode',
),
'IDField' => 'EmailMessageId',
'TitleField' => 'Subject',
'TableName' => TABLE_PREFIX.'EmailMessage',
'ListSQLs' => Array (
'' => ' SELECT %1$s.* %2$s
FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'Events ON '.TABLE_PREFIX.'Events.EventId = %1$s.EventId'
),
'ItemSQLs' => Array (
'' => ' SELECT %1$s.* %2$s
FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'Events ON '.TABLE_PREFIX.'Events.EventId = %1$s.EventId'
),
'ForeignKey' => 'LanguageId',
'ParentTableKey' => 'LanguageId',
'ParentPrefix' => 'lang',
'AutoDelete' => true,
'AutoClone' => true,
'CalculatedFields' => Array (
'' => Array (
'Description' => TABLE_PREFIX.'Events.Description',
'Module' => TABLE_PREFIX.'Events.Module',
'Type' => TABLE_PREFIX.'Events.Type',
'ReplacementTags' => TABLE_PREFIX.'Events.ReplacementTags',
),
),
'Fields' => Array (
'EmailMessageId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'Template' => Array('type' => 'string', 'default' => null),
- 'MessageType' => Array('type' => 'string', 'formatter' => 'kOptionsFormatter', 'options' => Array('text'=>'la_Text','html'=>'la_Html'), 'not_null' => '1','default' => 'text'),
+ 'MessageType' => Array('type' => 'string', 'formatter' => 'kOptionsFormatter', 'options' => Array('text'=>'la_Text','html'=>'la_Html'), 'use_phrases' => 1, 'not_null' => '1','default' => 'text'),
'LanguageId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'EventId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'Subject' => Array('type' => 'string', 'default' => null),
),
'VirtualFields' => Array (
'Headers' => Array('type'=>'string'),
'Body' => Array('type'=>'string'),
'ReplacementTags' => Array ('type' => 'string', 'default' => null),
'Description' => Array('type'=>'string', 'sql_filter_type'=>'having'),
'Module' => Array('type' => 'string','not_null' => '1','default' => ''),
'Type' => Array('formatter'=>'kOptionsFormatter', 'options' => Array (1 => 'la_Text_Admin', 0 => 'la_Text_User'), 'use_phrases' => 1, 'default' => 0, 'not_null' => 1),
// for mass mail sending
'MassSubject' => Array ('type' => 'string', 'default' => ''),
'MassAttachment' => Array ('type' => 'string', 'formatter' => 'kUploadFormatter', 'upload_dir' => '/kernel/downloads/', 'max_size' => 50000000, 'default' => ''),
'MassHtmlMessage' => Array ('type' => 'string', 'default' => 'Type your Message Here'),
'MassTextMessage' => Array ('type' => 'string', 'default' => 'Type your Message Here'),
),
'Grids' => Array(
'Default' => Array(
'Icons' => Array('default'=>'icon16_custom.gif'),
'Fields' => Array(
'Subject' => Array( 'title'=>'la_col_Subject'),
'Description' => Array( 'title'=>'la_col_Description', 'data_block' => 'label_grid_checkbox_td'),
'Type' => Array( 'title'=>'la_col_Type'),
),
),
),
);
?>
\ No newline at end of file
Property changes on: branches/RC/core/units/email_messages/email_messages_config.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.10.2.1
\ No newline at end of property
+1.10.2.2
\ No newline at end of property
Index: branches/RC/core/admin_templates/regional/email_messages_edit.tpl
===================================================================
--- branches/RC/core/admin_templates/regional/email_messages_edit.tpl (revision 10193)
+++ branches/RC/core/admin_templates/regional/email_messages_edit.tpl (revision 10194)
@@ -1,46 +1,49 @@
<inp2:adm_SetPopupSize width="827" height="400"/>
<inp2:m_RequireLogin permissions="in-portal:configure_lang.view" system="1"/>
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="section_header" icon="icon46_conf_regional" title="!la_title_Regional!"/>
<inp2:m_RenderElement name="blue_bar" prefix="lang" title_preset="email_messages_edit" module="in-portal" icon="icon46_conf_regional"/>
<!-- ToolBar --->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<script type="text/javascript">
a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
submit_event('emailmessages','<inp2:m_if check="emailmessages_PropertyEquals" property="ID" value="0" >OnCreate<inp2:m_else/>OnUpdate</inp2:m_if>');
}
) );
a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
submit_event('emailmessages','OnCancel');
}
) );
a_toolbar.Render();
</script>
</td>
</tr>
</tbody>
</table>
<inp2:lang_SaveWarning name="grid_save_warning"/>
-<table width="100%" border="0" cellspacing="0" cellpadding="4" class="bordered">
- <inp2:m_RenderElement name="subsection" title="!la_section_General!"/>
- <inp2:m_RenderElement name="inp_edit_hidden" prefix="emailmessages" field="LanguageId"/>
- <inp2:m_RenderElement name="inp_edit_hidden" prefix="emailmessages" field="EventId"/>
- <!-- <inp2:m_RenderElement name="inp_label" prefix="emailmessages" field="Type" title="!la_fld_EventType!"/> -->
- <inp2:m_RenderElement name="inp_edit_box" prefix="emailmessages" field="Subject" title="!la_fld_Subject!" size="60"/>
- <inp2:m_RenderElement name="inp_edit_radio" prefix="emailmessages" field="MessageType" title="!la_fld_MessageType!"/>
- <inp2:m_RenderElement name="inp_edit_textarea" prefix="emailmessages" field="Headers" title="!la_fld_ExtraHeaders!" rows="5" cols="60"/>
- <inp2:m_RenderElement name="subsection" title="!la_section_Message!"/>
- <inp2:m_RenderElement name="inp_edit_textarea" prefix="emailmessages" field="Body" title="!la_fld_MessageBody!" rows="20" cols="85"/>
-</table>
+
+<div id="scroll_container">
+ <table class="edit-form">
+ <inp2:m_RenderElement name="subsection" title="!la_section_General!"/>
+ <inp2:m_RenderElement name="inp_edit_hidden" prefix="emailmessages" field="LanguageId"/>
+ <inp2:m_RenderElement name="inp_edit_hidden" prefix="emailmessages" field="EventId"/>
+ <!-- <inp2:m_RenderElement name="inp_label" prefix="emailmessages" field="Type" title="!la_fld_EventType!"/> -->
+ <inp2:m_RenderElement name="inp_edit_box" prefix="emailmessages" field="Subject" title="!la_fld_Subject!" size="60"/>
+ <inp2:m_RenderElement name="inp_edit_radio" prefix="emailmessages" field="MessageType" title="!la_fld_MessageType!"/>
+ <inp2:m_RenderElement name="inp_edit_textarea" prefix="emailmessages" field="Headers" title="!la_fld_ExtraHeaders!" control_options="{min_height: 100}" rows="5" cols="60"/>
+ <inp2:m_RenderElement name="subsection" title="!la_section_Message!"/>
+ <inp2:m_RenderElement name="inp_edit_textarea" prefix="emailmessages" field="Body" title="!la_fld_MessageBody!" control_options="{min_height: 200}" rows="20" cols="85"/>
+ </table>
+</div>
<inp2:m_include t="incs/footer"/>
Property changes on: branches/RC/core/admin_templates/regional/email_messages_edit.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.4.2.1
\ No newline at end of property

Event Timeline