Index: branches/5.2.x/core/admin_templates/logs/email_logs/email_log_list.tpl =================================================================== diff -u -N -r14244 -r15230 --- branches/5.2.x/core/admin_templates/logs/email_logs/email_log_list.tpl (.../email_log_list.tpl) (revision 14244) +++ branches/5.2.x/core/admin_templates/logs/email_logs/email_log_list.tpl (.../email_log_list.tpl) (revision 15230) @@ -14,9 +14,15 @@ function edit() { - + std_edit_temp_item('email-log', 'logs/email_logs/email_log_edit'); } + + edit(); + + + a_toolbar.AddButton( new ToolBarSeparator('sep1') ); + a_toolbar.AddButton( new ToolBarButton( 'refresh', @@ -39,14 +45,12 @@ ) ); - a_toolbar.AddButton( new ToolBarSeparator('sep1') ); + a_toolbar.AddButton( new ToolBarSeparator('sep2') ); + + show_viewmenu(a_toolbar,'view'); + - a_toolbar.AddButton( new ToolBarButton('view', '', function(id) { - show_viewmenu(a_toolbar,'view'); - } - ) ); - a_toolbar.Render(); @@ -61,4 +65,8 @@ + + Index: branches/5.2.x/core/kernel/utility/email.php =================================================================== diff -u -N -r15225 -r15230 --- branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15225) +++ branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15230) @@ -1,6 +1,6 @@ sender->SetEncodedHeader($header_name, $header_value); } - // 2. set body + if ( $this->_storeEmailLog() ) { + // 2. prepare log + $log_fields_hash = Array ( + 'From' => $this->fromName . ' (' . $this->fromEmail . ')', + 'To' => $this->toName . ' (' . $this->toEmail . ')', + 'OtherRecipients' => serialize($this->recipients), + 'Subject' => $message_subject, + 'SentOn' => TIMENOW, + 'EventName' => $this->emailEvent->GetDBField('Event'), + 'EventParams' => serialize($this->_getCustomParams()), + ); + + $this->params['email_access_key'] = $this->_generateAccessKey($log_fields_hash); + } + + // 3. set body $html_message_body = $this->_getMessageBody(true); $plain_message_body = $this->_getMessageBody(false); @@ -258,22 +273,48 @@ $this->_changeLanguage(true); - // 3. set log - $log_fields_hash = Array ( - 'fromuser' => $this->fromName . ' (' . $this->fromEmail . ')', - 'addressto' => $this->toName . ' (' . $this->toEmail . ')', - 'subject' => $message_subject, - 'timestamp' => TIMENOW, - 'event' => $this->emailEvent->GetDBField('Event'), - 'EventParams' => serialize($this->_getCustomParams()), - ); + if ( $this->_storeEmailLog() ) { + // 4. set log + $log_fields_hash['HtmlBody'] = $html_message_body; + $log_fields_hash['TextBody'] = $plain_message_body; + $log_fields_hash['AccessKey'] = $this->params['email_access_key']; + $this->sender->setLogData($log_fields_hash); + } - $this->sender->setLogData($log_fields_hash); - return $this->sender->Deliver(null, $immediate_send); } /** + * Determines whatever we should keep e-mail log or not + * + * @return bool + * @access protected + */ + protected function _storeEmailLog() + { + return $this->Application->ConfigValue('EmailLogRotationInterval') != ''; + } + + /** + * Generates access key for accessing e-mail later + * + * @param Array $log_fields_hash + * @return string + * @access protected + */ + protected function _generateAccessKey($log_fields_hash) + { + $ret = ''; + $use_fields = Array ('From', 'To', 'Subject'); + + foreach ($use_fields as $use_field) { + $ret .= $log_fields_hash[$use_field] . ':'; + } + + return md5($ret . microtime(true)); + } + + /** * Processes email sender * * @return void @@ -373,25 +414,24 @@ ); $default_email = $this->Application->ConfigValue('DefaultEmailSender'); + $this->recipients = array_map(Array ($this, '_transformRecipientsIntoPairs'), $this->recipients); foreach ($this->recipients as $recipient_type => $recipients) { // add recipients to email - $pairs = $this->_transformRecipientsIntoPairs($recipients); - - if ( !$pairs ) { + if ( !$recipients ) { continue; } if ( $recipient_type == EmailEvent::RECIPIENT_TYPE_TO ) { - $this->toEmail = $pairs[0]['email'] ? $pairs[0]['email'] : $default_email; - $this->toName = $pairs[0]['name'] ? $pairs[0]['name'] : $this->toEmail; + $this->toEmail = $recipients[0]['email'] ? $recipients[0]['email'] : $default_email; + $this->toName = $recipients[0]['name'] ? $recipients[0]['name'] : $this->toEmail; } $header_name = $header_mapping[$recipient_type]; - foreach ($pairs as $pair) { - $email = $pair['email'] ? $pair['email'] : $default_email; - $name = $pair['name'] ? $pair['name'] : $email; + foreach ($recipients as $recipient) { + $email = $recipient['email'] ? $recipient['email'] : $default_email; + $name = $recipient['name'] ? $recipient['name'] : $email; $this->sender->AddRecipient($header_name, $email, $name); } @@ -683,6 +723,7 @@ * @param bool $is_html * @return string * @access protected + * @todo maybe ConvertToText will strip all getObject($params); + /* @var $object kDBItem */ + + $other_recipients = $object->GetDBField('OtherRecipients'); + $other_recipients = $other_recipients ? unserialize($other_recipients) : Array (); + + $ret = ''; + $block_params = $this->prepareTagParams($params); + $block_params['name'] = $params['render_as']; + + foreach ($other_recipients as $recipient_type => $recipients) { + if ( $recipient_type == EmailEvent::RECIPIENT_TYPE_TO ) { + array_shift($recipients); + } + + if ( $recipients ) { + $block_params['recipient_type'] = $recipient_type; + $block_params['recipients'] = $recipients; + + $ret .= $this->Application->ParseBlock($block_params); + } + } + + return $ret; + } + + /** + * Returns recipient type + * + * @param Array $params + * @return string + * @access protected + */ + protected function RecipientType($params) + { + $heading_mapping = Array ( + EmailEvent::RECIPIENT_TYPE_TO => 'To', + EmailEvent::RECIPIENT_TYPE_CC => 'Cc', + EmailEvent::RECIPIENT_TYPE_BCC => 'Bcc', + ); + + $recipient_type = $this->Application->Parser->GetParam('recipient_type'); + + return $heading_mapping[$recipient_type]; + } + + /** + * Prints recipients + * + * @param Array $params + * @return string + * @access protected + */ + protected function RecipientsByType($params) + { + $recipients = $this->Application->Parser->GetParam('recipients'); + /* @var $recipients Array */ + + $ret = ''; + $block_params = $this->prepareTagParams($params); + $block_params['name'] = $params['render_as']; + + $recipient_count = count($recipients); + + foreach ($recipients as $index => $recipient) { + $block_params['recipient_name'] = $recipient['name'] ? $recipient['name'] : $recipient['email']; + $block_params['recipient_email'] = $recipient['email']; + $block_params['is_last'] = $index == $recipient_count - 1; + + $ret .= $this->Application->ParseBlock($block_params); + } + + return $ret; + } + + /** + * Creates link to an item including only it's id + * + * @param Array $params + * @return string + * @access protected + */ + protected function ItemLink($params) + { + $access_key = $this->Application->Parser->GetParam('email_access_key'); + + if ( !$access_key ) { + return parent::ItemLink($params); + } + + $params['authkey'] = $access_key; + + if ( $this->Application->isAdmin ) { +// $params['index_file'] = 'index.php'; + $params['prefix'] = '_FRONT_END_'; + + if ( $this->Application->ConfigValue('UseModRewrite') ) { + $params['__MOD_REWRITE__'] = 1; + } + } + + return $this->Application->ProcessParsedTag('m', 't', $params); + } +} \ No newline at end of file Index: branches/5.2.x/core/install/install_data.sql =================================================================== diff -u -N -r15163 -r15230 --- branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15163) +++ branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15230) @@ -89,6 +89,7 @@ INSERT INTO SystemSettings VALUES(DEFAULT, 'MailingListQueuePerStep', '10', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_MailingListQueuePerStep', 'text', NULL, NULL, 50.08, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'MailingListSendPerStep', '10', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_MailingListSendPerStep', 'text', NULL, NULL, 50.09, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'DefaultEmailRecipients', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_DefaultEmailRecipients', 'text', NULL, NULL, 50.10, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailLogRotationInterval', '2419200', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_EmailLogRotationInterval', 'select', NULL, '=la_opt_EmailLogKeepNever||86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_EmailLogKeepForever', 50.11, 0, 0, 'hint:la_config_EmailLogRotationInterval'); INSERT INTO SystemSettings VALUES(DEFAULT, 'UseOutputCompression', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_UseOutputCompression', 'checkbox', '', '', 60.01, 0, 1, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'OutputCompressionLevel', '7', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_OutputCompressionLevel', 'text', '', '', 60.02, 0, 1, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'UseTemplateCompression', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_UseTemplateCompression', 'checkbox', '', '', 60.03, 0, 1, NULL); @@ -633,6 +634,7 @@ INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:sessionlog.view', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:sessionlog.delete', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:emaillog.view', 11, 1, 1, 0); +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:emaillog.edit', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:emaillog.delete', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:visits.view', 11, 1, 1, 0); INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:visits.delete', 11, 1, 1, 0); Index: branches/5.2.x/admin/system_presets/simple/email_logs_email-log.php =================================================================== diff -u -N -r15024 -r15230 --- branches/5.2.x/admin/system_presets/simple/email_logs_email-log.php (.../email_logs_email-log.php) (revision 15024) +++ branches/5.2.x/admin/system_presets/simple/email_logs_email-log.php (.../email_logs_email-log.php) (revision 15230) @@ -9,18 +9,18 @@ // section in debug mode $debug_only_sections = Array ( - 'in-portal:searchlog', + 'in-portal:emaillog', ); // toolbar buttons $remove_buttons = Array ( // list of sent emails -// 'email_log_list' => Array ('refresh', 'reset', 'view'), +// 'email_log_list' => Array ('edit', 'refresh', 'reset', 'view'), ); // fields to hide $hidden_fields = Array ( - /*'EmailLogId', 'fromuser', 'addressto', 'subject', 'timestamp', 'event', 'EventParams'*/ + /*'EmailLogId', 'From', 'To', 'OtherRecipients', 'Subject', 'HtmlBody', 'TextBody', 'SentOn', 'EventName', 'EventParams', 'AccessKey'*/ ); // virtual fields to hide @@ -30,7 +30,7 @@ // fields to make required $required_fields = Array ( - /*'EmailLogId', 'fromuser', 'addressto', 'subject', 'timestamp', 'event', 'EventParams'*/ + /*'EmailLogId', 'From', 'To', 'OtherRecipients', 'Subject', 'HtmlBody', 'TextBody', 'SentOn', 'EventName', 'EventParams', 'AccessKey'*/ ); // virtual fields to make required @@ -46,5 +46,5 @@ // hide columns in grids $hide_columns = Array ( // currently not in user -// 'Default' => Array ('EmailLogId', 'fromuser', 'addressto', 'subject', 'timestamp', 'event'), +// 'Default' => Array ('EmailLogId', 'From', 'To', 'Subject', 'SentOn', 'EventName'), ); \ No newline at end of file Index: branches/5.2.x/core/units/logs/email_logs/email_log_eh.php =================================================================== diff -u -N --- branches/5.2.x/core/units/logs/email_logs/email_log_eh.php (revision 0) +++ branches/5.2.x/core/units/logs/email_logs/email_log_eh.php (revision 15230) @@ -0,0 +1,126 @@ + Array ('self' => true), + 'OnGetHtmlBody' => Array ('self' => 'edit'), + ); + + $this->permMapping = array_merge($this->permMapping, $permissions); + } + + /** + * Returns ID of current item to be edited + * by checking ID passed in get/post as prefix_id + * or by looking at first from selected ids, stored. + * Returned id is also stored in Session in case + * it was explicitly passed as get/post + * + * @param kEvent $event + * @return int + * @access public + */ + public function getPassedID(kEvent $event) + { + if ( $this->Application->isAdmin ) { + return parent::getPassedID($event); + } + + $authkey = $this->Application->GetVar('authkey'); + + return $authkey ? Array ('AccessKey' => $authkey) : false; + } + + /** + * [SCHEDULED TASK] Will remove old e-mail logs + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnRotate(kEvent $event) + { + $rotation_interval = $this->Application->ConfigValue('EmailLogRotationInterval'); + + if ( $rotation_interval == '' || $rotation_interval == -1 ) { + // never OR forever + return; + } + + $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE ' . TIMENOW . ' - SentOn > ' . $rotation_interval; + $ids = $this->Conn->GetCol($sql); + + if ( $ids ) { + $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event)); + /* @var $temp_handler kTempTablesHandler */ + + $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); + } + } + + /** + * Returns HTML of sent e-mail for iframe + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnGetHtmlBody(kEvent $event) + { + $event->status = kEvent::erSTOP; + + $object = $event->getObject(); + /* @var $object kDBItem */ + + echo $object->GetDBField('HtmlBody'); + } + + /** + * Checks, that currently loaded item is allowed for viewing (non permission-based) + * + * @param kEvent $event + * @return bool + * @access protected + */ + protected function checkItemStatus(kEvent $event) + { + $object = $event->getObject(); + /* @var $object kDBItem */ + + if ( !$object->isLoaded() ) { + return true; + } + + $access_key = $object->GetDBField('AccessKey'); + + return $access_key && $this->Application->GetVar('authkey') == $access_key; + } +} \ No newline at end of file Index: branches/5.2.x/core/install/install_schema.sql =================================================================== diff -u -N -r15225 -r15230 --- branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15225) +++ branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15230) @@ -389,14 +389,18 @@ CREATE TABLE EmailLog ( EmailLogId int(11) NOT NULL AUTO_INCREMENT, - fromuser varchar(200) DEFAULT NULL, - addressto varchar(255) DEFAULT NULL, - `subject` varchar(255) DEFAULT NULL, - `timestamp` bigint(20) DEFAULT '0', - `event` varchar(100) DEFAULT NULL, + `From` varchar(255) NOT NULL DEFAULT '', + `To` varchar(255) NOT NULL DEFAULT '', + OtherRecipients text, + `Subject` varchar(255) NOT NULL DEFAULT '', + HtmlBody longtext, + TextBody longtext, + SentOn int(11) DEFAULT NULL, + EventName varchar(255) NOT NULL DEFAULT '', EventParams text, + AccessKey varchar(32) NOT NULL DEFAULT '', PRIMARY KEY (EmailLogId), - KEY `timestamp` (`timestamp`) + KEY `timestamp` (SentOn) ); CREATE TABLE SystemCache ( Index: branches/5.2.x/core/install/upgrades.sql =================================================================== diff -u -N -r15225 -r15230 --- branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15225) +++ branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15230) @@ -2663,3 +2663,23 @@ ALTER TABLE Languages ADD HtmlEmailTemplate TEXT NULL, ADD TextEmailTemplate TEXT NULL; + +ALTER TABLE EmailLog CHANGE fromuser `From` VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE EmailLog CHANGE addressto `To` VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE EmailLog CHANGE subject `Subject` VARCHAR(255) NOT NULL DEFAULT ''; +ALTER TABLE EmailLog CHANGE `timestamp` SentOn INT(11) NULL; +ALTER TABLE EmailLog CHANGE `event` EventName VARCHAR(255) NOT NULL DEFAULT ''; + +ALTER TABLE EmailLog ADD OtherRecipients TEXT NULL AFTER `To`; + +ALTER TABLE EmailLog + ADD HtmlBody LONGTEXT NULL AFTER `Subject`, + ADD TextBody LONGTEXT NULL AFTER HtmlBody; + +ALTER TABLE EmailLog ADD AccessKey VARCHAR(32) NOT NULL DEFAULT ''; + +INSERT INTO Permissions VALUES (DEFAULT, 'in-portal:emaillog.edit', 11, 1, 1, 0); + +DELETE FROM LanguageLabels WHERE PhraseKey = 'LA_PROMPT_FROMUSERNAME'; + +INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailLogRotationInterval', '-1', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_EmailLogRotationInterval', 'select', NULL, '=la_opt_EmailLogKeepNever||86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_EmailLogKeepForever', 50.11, 0, 0, 'hint:la_config_EmailLogRotationInterval'); Index: branches/5.2.x/core/units/helpers/mailing_list_helper.php =================================================================== diff -u -N -r15137 -r15230 --- branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 15137) +++ branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 15230) @@ -1,6 +1,6 @@ SetFrom($mailing_data['FromEmail'], $mailing_data['FromName']); $esender->SetSubject($mailing_data['Subject']); + if ( !$mailing_data['MessageText'] ) { + $mailing_data['MessageText'] = $esender->ConvertToText($mailing_data['MessageHtml']); + } + $esender->SetBody($mailing_data['MessageHtml'], $mailing_data['MessageText']); // 2. add attachment if any @@ -56,16 +60,21 @@ // 3. set recipient specific fields $esender->SetTo($email, $email); - // 4. write to log - $log_fields_hash = Array ( - 'fromuser' => $mailing_data['FromName'] . '<' . $mailing_data['FromEmail'] . '>', - 'addressto' => $email, - 'subject' => $mailing_data['Subject'], - 'timestamp' => adodb_mktime(), - 'EventParams' => serialize( Array ('MailingId' => $mailing_id) ), - ); + if ( $this->Application->ConfigValue('EmailLogRotationInterval') != '' ) { + // 4. write to log + $log_fields_hash = Array ( + 'From' => $mailing_data['FromName'] . '(' . $mailing_data['FromEmail'] . ')', + 'To' => $email, + 'Subject' => $mailing_data['Subject'], + 'HtmlBody' => $mailing_data['MessageHtml'], + 'TextBody' => $mailing_data['MessageText'], + 'SentOn' => TIMENOW, + 'EventParams' => serialize( Array ('MailingId' => $mailing_id) ), + ); - $esender->setLogData($log_fields_hash); + $esender->setLogData($log_fields_hash); + } + $esender->Deliver(null, $mailing_id, false); } Index: branches/5.2.x/core/admin_templates/logs/email_logs/email_log_edit.tpl =================================================================== diff -u -N --- branches/5.2.x/core/admin_templates/logs/email_logs/email_log_edit.tpl (revision 0) +++ branches/5.2.x/core/admin_templates/logs/email_logs/email_log_edit.tpl (revision 15230) @@ -0,0 +1,102 @@ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + + + + + + + + + + <> + ; + + + + : + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+
+ + \ No newline at end of file Index: branches/5.2.x/core/units/logs/email_logs/email_logs_config.php =================================================================== diff -u -N -r14585 -r15230 --- branches/5.2.x/core/units/logs/email_logs/email_logs_config.php (.../email_logs_config.php) (revision 14585) +++ branches/5.2.x/core/units/logs/email_logs/email_logs_config.php (.../email_logs_config.php) (revision 15230) @@ -1,6 +1,6 @@ 'email-log', 'ItemClass' => Array('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), 'ListClass' => Array('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), - 'EventHandlerClass' => Array ('class' => 'kDBEventHandler', 'file' => '', 'build_event' => 'OnBuild'), - 'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'), + 'EventHandlerClass' => Array ('class' => 'EmailLogEventHandler', 'file' => 'email_log_eh.php', 'build_event' => 'OnBuild'), + 'TagProcessorClass' => Array ('class' => 'EmailLogTagProcessor', 'file' => 'email_log_tp.php', 'build_event' => 'OnBuild'), 'AutoLoad' => true, @@ -31,12 +31,22 @@ 5 => 'mode', ), + 'ScheduledTasks' => Array( + 'rotate_email_logs' => Array('EventName' => 'OnRotate', 'RunInterval' => 86400), + ), + 'IDField' => 'EmailLogId', 'TableName' => TABLE_PREFIX . 'EmailLog', + 'TitleField' => 'EmailLogId', + 'TitlePresets' => Array ( - 'email_log_list' => Array ('prefixes' => Array('email-log_List'), 'format' => '!la_tab_EmailLog!',), + 'email_log_list' => Array ('prefixes' => Array('email-log_List'), 'format' => '!la_tab_EmailLog!'), + + 'email_log_edit' => Array ( + 'prefixes' => Array ('email-log'), 'format' => "!la_title_ViewingEmailLog! '#email-log_titlefield#'", + ), ), 'PermSection' => Array ('main' => 'in-portal:emaillog'), @@ -47,7 +57,7 @@ 'icon' => 'email_log', 'label' => 'la_tab_EmailLog', 'url' => Array('t' => 'logs/email_logs/email_log_list', 'pass' => 'm'), - 'permissions' => Array ('view', 'delete'), + 'permissions' => Array ('view', 'edit', 'delete'), 'priority' => 5, 'type' => stTREE, ), @@ -59,31 +69,34 @@ 'ListSortings' => Array ( '' => Array ( - 'Sorting' => Array ('timestamp' => 'desc'), + 'Sorting' => Array ('SentOn' => 'desc'), ) ), 'Fields' => Array ( 'EmailLogId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), - 'fromuser' => Array ('type' => 'string', 'max_len' => 200, 'default' => NULL), - 'addressto' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL), - 'subject' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL), - 'timestamp' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), - 'event' => Array ('type' => 'string', 'max_len' => 100, 'default' => NULL), + 'From' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + 'To' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + 'OtherRecipients' => Array ('type' => 'string', 'default' => NULL), + 'Subject' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + 'HtmlBody' => Array ('type' => 'string', 'default' => NULL), + 'TextBody' => Array ('type' => 'string', 'default' => NULL), + 'SentOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), + 'EventName' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), 'EventParams' => Array ('type' => 'string', 'default' => NULL), + 'AccessKey' => Array ('type' => 'string', 'max_len' => 20, 'not_null' => 1, 'default' => ''), ), 'Grids' => Array ( 'Default' => Array ( - 'Icons' => Array ('default' => 'icon16_item.png'), 'Fields' => Array ( - 'EmailLogId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 50, ), - 'fromuser' => Array ('title' => 'la_prompt_FromUsername', 'filter_block' => 'grid_like_filter', 'width' => 200, ), - 'addressto' => Array ('title' => 'la_prompt_AddressTo', 'filter_block' => 'grid_like_filter', 'width' => 200, ), - 'subject' => Array ('filter_block' => 'grid_like_filter', 'width' => 200, ), - 'event' => Array ('filter_block' => 'grid_like_filter', 'width' => 170, ), - 'timestamp' => Array ('title' => 'la_prompt_SentOn', 'filter_block' => 'grid_date_range_filter', 'width' => 145, ), -// 'EventParams' => Array ('title' => 'la_col_EventParams', 'filter_block' => 'grid_like_filter', ), + 'EmailLogId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 80), + 'From' => Array ('title' => 'column:la_fld_Sender', 'filter_block' => 'grid_like_filter', 'width' => 200), + 'To' => Array ('title' => 'column:la_fld_Recipient', 'filter_block' => 'grid_like_filter', 'width' => 200), + 'Subject' => Array ('filter_block' => 'grid_like_filter', 'width' => 200), + 'EventName' => Array ('title' => 'column:la_fld_Event', 'filter_block' => 'grid_like_filter', 'width' => 170), + 'SentOn' => Array ('title' => 'la_prompt_SentOn', 'filter_block' => 'grid_date_range_filter', 'width' => 145), +// 'EventParams' => Array ('title' => 'la_col_EventParams', 'filter_block' => 'grid_like_filter'), ), ), ), Index: branches/5.2.x/core/units/mailing_lists/mailing_list_eh.php =================================================================== diff -u -N -r15145 -r15230 --- branches/5.2.x/core/units/mailing_lists/mailing_list_eh.php (.../mailing_list_eh.php) (revision 15145) +++ branches/5.2.x/core/units/mailing_lists/mailing_list_eh.php (.../mailing_list_eh.php) (revision 15230) @@ -1,6 +1,6 @@ SetDBField('To', $to); } + + $this->setRequired($event); } /** + * Prepare recipient list + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnPreCreate(kEvent $event) + { + parent::OnPreCreate($event); + + $this->setRequired($event); + } + + /** * Don't allow to delete mailings in progress * * @param kEvent $event @@ -164,17 +180,45 @@ $object->SetDBField('To', implode(';', $recipients)); } - if ( !$object->GetDBField('MessageText') ) { - $object->setRequired('MessageHtml'); - } - // remember user, who created mailing, because of his name // is needed for "From" field, but mailing occurs from cron $user_id = $this->Application->RecallVar('user_id'); $object->SetDBField('PortalUserId', $user_id); + + $this->setRequired($event); } /** + * Checks, that at least one message text field is filled + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemUpdate(kEvent $event) + { + parent::OnBeforeItemUpdate($event); + + $this->setRequired($event); + } + + /** + * Dynamically changes required fields + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function setRequired(kEvent $event) + { + $object = $event->getObject(); + /* @var $object kDBItem */ + + $object->setRequired('MessageHtml', !$object->GetDBField('MessageText')); + $object->setRequired('MessageText', !$object->GetDBField('MessageHtml')); + } + + /** * Deletes mailing list email queue, when it becomes cancelled * * @param kEvent $event Index: branches/5.2.x/core/install/english.lang =================================================================== diff -u -N -r15225 -r15230 --- branches/5.2.x/core/install/english.lang (.../english.lang) (revision 15225) +++ branches/5.2.x/core/install/english.lang (.../english.lang) (revision 15230) @@ -1,7 +1,7 @@ - JGJvZHkNCjxici8+PGJyLz4NCg0KU2luY2VyZWx5LDxici8+PGJyLz4NCg0KV2Vic2l0ZSBhZG1pbmlzdHJhdGlvbi4= + JGJvZHkNCjxici8+PGJyLz4NCg0KU2luY2VyZWx5LDxici8+PGJyLz4NCg0KV2Vic2l0ZSBhZG1pbmlzdHJhdGlvbi4NCg0KPCEtLSMjIDxpbnAyOmVtYWlsLWxvZ19JdGVtTGluayB0ZW1wbGF0ZT0icGxhdGZvcm0vbXlfYWNjb3VudC9lbWFpbCIvPiAjIy0tPg== QWN0aXZl @@ -161,6 +161,7 @@ RGVmYXVsdCAiUGVyIFBhZ2UiIHNldHRpbmcgaW4gR3JpZHM= RGVmYXVsdCBSZWdpc3RyYXRpb24gQ291bnRyeQ== RGVmYXVsdCBBbmFseXRpY3MgVHJhY2tpbmcgQ29kZQ== + S2VlcCBFbWFpbCBMb2cgZm9y RW5hYmxlIFJldmlzaW9uIENvbnRyb2wgZm9yIFNlY3Rpb24gQ29udGVudA== VGVtcGxhdGUgZm9yICJGaWxlIG5vdCBmb3VuZCAoNDA0KSIgRXJyb3I= RXhjbHVkZSB0ZW1wbGF0ZSBiYXNlZCBTZWN0aW9ucyBmcm9tIFNlYXJjaCBSZXN1bHRzIChpZS4gVXNlciBSZWdpc3RyYXRpb24p @@ -536,6 +537,7 @@ T3B0aW9ucw== T3B0aW9uIFRpdGxl T3JkZXI= + T3RoZXIgUmVjaXBpZW50cw== T3ZlcndyaXRlIERlZmF1bHQgQ2FjaGluZyBLZXk= UGFjayBOYW1l UGFkZGluZyBCb3R0b20= @@ -569,6 +571,7 @@ UHJvdGVjdGVk UXVhbnRpdHk= UmF0aW5n + UmVjaXBpZW50 UmVjaXBpZW50J3MgQWRkcmVzcw== UmVjaXBpZW50J3MgQWRkcmVzcyBUeXBl UmVjaXBpZW50J3MgTmFtZQ== @@ -602,6 +605,7 @@ U2FtZSBBcyBUaHVtYg== U2NoZWR1bGUgRGF0ZQ== U2VhcmNoIFRlcm0= + U2VuZGVy U2VuZGVyJ3MgQWRkcmVzcw== U2VuZGVyJ3MgTmFtZQ== U2VudCBPbg== @@ -783,6 +787,8 @@ RS1tYWls RS1tYWlsIEJvZHk= RS1tYWlsIEV2ZW50cw== + Rm9yZXZlciAobmV2ZXIgZGVsZXRlZCBhdXRvbWF0aWNhbGx5KQ== + TmV2ZXIgKHR1cm5lZCBvZmYp RS1tYWlsIFN1YmplY3Q= RXZlcnlvbmU= RXhhY3Q= @@ -809,6 +815,10 @@ Tm90IGxpa2U= Tm90IFByb2Nlc3NlZA== Tm90IFJlcGxpZWQ= + MSBkYXk= + MSBtb250aA== + MSB3ZWVr + MSB5ZWFy UGFydGlhbGx5IFByb2Nlc3NlZA== UGVuZGluZw== UGhvbmU= @@ -834,7 +844,9 @@ U3lzdGVt VGFi VGVtcGxhdGU= + MyBtb250aHM= VGl0bGU= + MiB3ZWVrcw== VXNlcg== RW1haWwgQWN0aXZhdGlvbg== SW1tZWRpYXRlIA== @@ -938,7 +950,6 @@ RmllbGQgTmFtZQ== RmllbGQgUHJvbXB0 RnJlcXVlbmN5 - RnJvbQ== SGVhZGluZw== KE1pbmltdW0gNCk= SW1wb3J0IFNvdXJjZQ== @@ -1404,6 +1415,7 @@ VGhlc2F1cnVz VXBkYXRpbmcgU2VjdGlvbnM= VXNlcnM= + Vmlld2luZyBFbWFpbCBMb2c= Vmlld2luZyBmb3JtIHN1Ym1pc3Npb24= Vmlld2luZyBNYWlsaW5nIExpc3Q= Vmlld2luZyBSZXBseQ==