Index: branches/RC/core/units/email_events/email_events_config.php
===================================================================
diff -u -r8929 -r9047
--- branches/RC/core/units/email_events/email_events_config.php (.../email_events_config.php) (revision 8929)
+++ branches/RC/core/units/email_events/email_events_config.php (.../email_events_config.php) (revision 9047)
@@ -23,6 +23,7 @@
'TitlePresets' => Array(
'email_settings_list' => Array('prefixes' => Array('emailevents.module_List'), 'format' => '!la_title_EmailSettings! (#emailevents.module_recordcount#)'),
+ 'email_send_form' => Array('prefixes' => Array(), 'format' => '!la_title_SendEmail!'),
'email_send' => Array('prefixes' => Array(), 'format' => '!la_title_PleaseWait!'),
'email_send_complete' => Array('prefixes' => Array(), 'format' => '!la_title_SendMailComplete!'),
),
Index: branches/RC/core/units/email_messages/email_messages_config.php
===================================================================
diff -u -r8929 -r9047
--- branches/RC/core/units/email_messages/email_messages_config.php (.../email_messages_config.php) (revision 8929)
+++ branches/RC/core/units/email_messages/email_messages_config.php (.../email_messages_config.php) (revision 9047)
@@ -1,90 +1,87 @@
'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'),
-$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'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
- 'AutoLoad' => true,
+ 'AutoLoad' => true,
- 'QueryString' => Array(
- 1 => 'id',
- 2 => 'page',
- 3 => 'event',
- 4 => 'mode',
- ),
+ 'QueryString' => Array (
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ 4 => 'mode',
+ ),
- 'IDField' => 'EmailMessageId',
+ 'IDField' => 'EmailMessageId',
+ 'TitleField' => 'Subject',
- 'TitleField' => 'Subject',
+ 'TableName' => TABLE_PREFIX.'EmailMessage',
- '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'
+ ),
- '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'
+ ),
- '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,
- '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',
+ ),
+ ),
- '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'),
+ 'LanguageId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'EventId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'Subject' => Array('type' => 'string', 'default' => null),
+ ),
- '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'),
- '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),
- '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'),
- ),
+ '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
Index: branches/RC/core/units/email_messages/email_messages_event_handler.php
===================================================================
diff -u -r8929 -r9047
--- branches/RC/core/units/email_messages/email_messages_event_handler.php (.../email_messages_event_handler.php) (revision 8929)
+++ branches/RC/core/units/email_messages/email_messages_event_handler.php (.../email_messages_event_handler.php) (revision 9047)
@@ -151,6 +151,167 @@
{
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 ;
+ }
+
+ $esender =& $this->Application->recallObject('EmailSender');
+ /* @var $esender kEmailSendingHelper */
+
+ $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'];
+ }
+
+ $recipients = $this->getRecipientEmails();
+ foreach ($recipients as $recipient_email) {
+ $this->sendMessage($fields_hash, $recipient_email, $esender);
+ }
+
+ // remove any temporary data
+ $this->Application->RemoveVar('recipient_ids');
+ $this->Application->RemoveVar('recipient_type');
+ $this->Application->RemoveVar('email_queue_progress');
+ if ($fields_hash['MassAttachment']) {
+ unlink(FULL_PATH.$fields_hash['MassAttachment']);
+ }
+
+ $event->redirect = 'emails/send_queue';
+ }
+
+
+ function getRecipientEmails()
+ {
+ $recipient_type = $this->Application->RecallVar('recipient_type');
+ $recipient_ids = $this->Application->RecallVar('recipient_ids');
+
+ if ($recipient_type == 'u') {
+ $sql = 'SELECT Email
+ FROM '.TABLE_PREFIX.'PortalUser
+ WHERE PortalUserId IN ('.$recipient_ids.')';
+ }
+ else {
+ $sql = 'SELECT u.Email
+ FROM '.TABLE_PREFIX.'UserGroup ug
+ LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON ug.PortalUserId = u.PortalUserId
+ WHERE ug.GroupId IN ('.$recipient_ids.')';
+ }
+
+ return $this->Conn->GetCol($sql);
+ }
+
+ /**
+ * Puts message to email queue for sending
+ *
+ * @param Array $fields_hash
+ * @param string $to_email recipient's email address
+ * @param kEmailSendingHelper $esender
+ */
+ function sendMessage($fields_hash, $to_email, &$esender)
+ {
+ $esender->SetFrom($fields_hash['FromEmail'], $fields_hash['FromName']);
+
+ $esender->AddTo($to_email);
+ $esender->SetSubject($fields_hash['MassSubject']);
+ $esender->SetBody($fields_hash['MassHtmlMessage'], $fields_hash['MassTextMessage']);
+
+ // add attachment if any
+ if ($fields_hash['MassAttachment']) {
+ $esender->AddAttachment(FULL_PATH.$fields_hash['MassAttachment']);
+ }
+
+ $status = $esender->Deliver(null, false);
+
+ if ($status) {
+ // write to log
+ $fields_hash = Array (
+ 'fromuser' => $fields_hash['FromName'],
+ 'addressto' => $to_email,
+ 'subject' => $fields_hash['MassSubject'],
+ 'timestamp' => adodb_mktime(),
+ 'event' => '',
+ );
+
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'EmailLog');
+ }
+ }
+
+ /**
+ * 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
Index: branches/RC/core/admin_templates/emails/mass_mail.tpl
===================================================================
diff -u
--- branches/RC/core/admin_templates/emails/mass_mail.tpl (revision 0)
+++ branches/RC/core/admin_templates/emails/mass_mail.tpl (revision 9047)
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
">
+
+
+ :
+ |
+
+
+ <>
+
+ ;
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: branches/RC/core/units/email_messages/email_message_tp.php
===================================================================
diff -u
--- branches/RC/core/units/email_messages/email_message_tp.php (revision 0)
+++ branches/RC/core/units/email_messages/email_message_tp.php (revision 9047)
@@ -0,0 +1,39 @@
+Application->RecallVar('recipient_type');
+
+ $block_params = $this->prepareTagParams($params);
+ $block_params['name'] = $params['render_as'];
+
+ $recipients = $this->getRecipients($recipient_type);
+ $recipient_count = count($recipients);
+ $ret = '';
+
+ foreach ($recipients as $recipient_index => $recipient_name) {
+ $block_params['recipient_name'] = $recipient_name;
+ $block_params['not_last'] = $recipient_index < $recipient_count - 1;
+
+ $ret .= $this->Application->ParseBlock($block_params);
+ }
+
+ return $ret;
+ }
+
+ function getRecipients($prefix)
+ {
+ $id_field = $this->Application->getUnitOption($prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ $recipient_ids = $this->Application->RecallVar('recipient_ids');
+
+ $sql = 'SELECT '.($prefix == 'u' ? 'Email' : 'Name').'
+ FROM '.$table_name.'
+ WHERE '.$id_field.' IN ('.$recipient_ids.')';
+ return $this->Conn->GetCol($sql);
+ }
+ }
+
+?>
\ No newline at end of file
Index: branches/RC/core/admin_templates/groups/groups_list.tpl
===================================================================
diff -u -r8929 -r9047
--- branches/RC/core/admin_templates/groups/groups_list.tpl (.../groups_list.tpl) (revision 8929)
+++ branches/RC/core/admin_templates/groups/groups_list.tpl (.../groups_list.tpl) (revision 9047)
@@ -38,6 +38,7 @@
a_toolbar.AddButton( new ToolBarButton('e-mail', '', function() {
openEmailSend('', 'group', 'g.total');
+// openSelector('emailmessages', '', 'UserEmail', null, 'OnPrepareMassRecipients');
}
) );
Index: branches/RC/kernel/admin_templates/users/users_list.tpl
===================================================================
diff -u -r8929 -r9047
--- branches/RC/kernel/admin_templates/users/users_list.tpl (.../users_list.tpl) (revision 8929)
+++ branches/RC/kernel/admin_templates/users/users_list.tpl (.../users_list.tpl) (revision 9047)
@@ -49,7 +49,7 @@
a_toolbar.AddButton( new ToolBarButton('in-portal:e-mail', '', function() {
- openSelector('u', '', 'UserEmail');
+ openSelector('emailmessages', '', 'UserEmail', null, 'OnPrepareMassRecipients');
}
) );
Index: branches/RC/core/kernel/utility/formatters/upload_formatter.php
===================================================================
diff -u -r8929 -r9047
--- branches/RC/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 8929)
+++ branches/RC/core/kernel/utility/formatters/upload_formatter.php (.../upload_formatter.php) (revision 9047)
@@ -89,19 +89,19 @@
$max_filesize = isset($options['max_size']) ? $options['max_size'] : MAX_UPLOAD_SIZE;
if (getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types'])) {
- $object->SetError($field_name, 'bad_file_format');
+ $object->SetError($field_name, 'bad_file_format', 'la_error_InvalidFileFormat');
}
elseif ($value['size'] > $max_filesize) {
- $object->SetError($field_name, 'bad_file_size');
+ $object->SetError($field_name, 'bad_file_size', 'la_error_FileTooLarge');
}
elseif (!is_writable($this->FullPath)) {
- $object->SetError($field_name, 'cant_save_file');
+ $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file');
}
else {
$real_name = $this->ValidateFileName($this->FullPath, $value['name']);
$file_name = $this->FullPath.$real_name;
if (!move_uploaded_file($value['tmp_name'], $file_name)) {
- $object->SetError($field_name, 'cant_save_file');
+ $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file');
}
else {
@chmod($file_name, 0666);
@@ -125,7 +125,7 @@
}
}
else {
- $object->SetError($field_name, 'cant_save_file');
+ $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file');
}
}
else {
@@ -136,7 +136,7 @@
// && !$object->FieldErrors[$field_name]['pseudo'] - already implemented in kDBItem::SetError method
if ((count($value) > 1) && $value['error'] && ($value['error'] != UPLOAD_ERR_NO_FILE)) {
- $object->SetError($field_name, 'cant_save_file');
+ $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file');
}
return $ret;
Index: branches/RC/kernel/admin_templates/groups/groups_list.tpl
===================================================================
diff -u -r8929 -r9047
--- branches/RC/kernel/admin_templates/groups/groups_list.tpl (.../groups_list.tpl) (revision 8929)
+++ branches/RC/kernel/admin_templates/groups/groups_list.tpl (.../groups_list.tpl) (revision 9047)
@@ -38,6 +38,7 @@
a_toolbar.AddButton( new ToolBarButton('e-mail', '', function() {
openEmailSend('', 'group', 'g.total');
+// openSelector('emailmessages', '', 'UserEmail', null, 'OnPrepareMassRecipients');
}
) );