From 6986a39eb5c217a5d5345bfa079e51fc1cd1ea70 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 8 Mar 2022 10:24:11 +0800 Subject: [PATCH] fix #7121 - crm fixes to email --- DataObjects/Core_email.php | 149 +++++++++++++++++++++++++++++++++++++ NotifySend.php | 15 ++-- Pman.Dialog.CoreEmail.bjs | 34 ++++----- Pman.Dialog.CoreEmail.js | 2 +- 4 files changed, 175 insertions(+), 25 deletions(-) diff --git a/DataObjects/Core_email.php b/DataObjects/Core_email.php index 0447e14a..8b3c0977 100644 --- a/DataObjects/Core_email.php +++ b/DataObjects/Core_email.php @@ -59,6 +59,155 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject bcc_group_id = {$cgm}.group_id ) AS bcc_group_member_count "); + + $this->selectAdd(" + ( + SELECT + COUNT(DISTINCT(crm_person_id)) + FROM + core_notify cn + WHERE + evtype = 'MAIL' + AND + person_table = 'crm_person' + AND + crm_person_id != 0 + AND + ontable = 'crm_mailing_list_queue' + AND + onid IN + ( + SELECT + id + FROM + crm_mailing_list_queue cmlq + WHERE message_id = crm_mailing_list_message.id + ) + AND + event_id > 0 + AND + sent IS NOT NULL + ) + + + ( + SELECT + COUNT(DISTINCT(person_id)) + FROM + core_notify cn + WHERE + evtype = 'MAIL' + AND + person_table = 'Person' + AND + person_id != 0 + AND + ontable = 'crm_mailing_list_queue' + AND + onid IN + ( + SELECT + id + FROM + crm_mailing_list_queue cmlq + WHERE message_id = crm_mailing_list_message.id + ) + AND + event_id > 0 + AND + sent IS NOT NULL + ) + AS sent_to_count + "); + + $this->selectAdd(" + ( + SELECT + COUNT(DISTINCT(crm_person_id)) + FROM + core_notify cn + WHERE + evtype = 'MAIL' + AND + person_table = 'crm_person' + AND + crm_person_id != 0 + AND + ontable = 'crm_mailing_list_queue' + AND + onid IN + ( + SELECT + id + FROM + crm_mailing_list_queue cmlq + WHERE message_id = crm_mailing_list_message.id + ) + AND + event_id > 0 + AND + sent IS NOT NULL + AND + is_open = 1 + ) + + + ( + SELECT + COUNT(DISTINCT(person_id)) + FROM + core_notify cn + WHERE + evtype = 'MAIL' + AND + person_table = 'Person' + AND + person_id != 0 + AND + ontable = 'crm_mailing_list_queue' + AND + onid IN + ( + SELECT + id + FROM + crm_mailing_list_queue cmlq + WHERE message_id = crm_mailing_list_message.id + ) + AND + event_id > 0 + AND + sent IS NOT NULL + AND + is_open = 1 + ) + AS opened_by_count + "); + + $this->selectAdd(" + ( + SELECT + MAX(sent) + FROM + core_notify cn + WHERE + evtype = 'MAIL' + AND + ontable = 'crm_mailing_list_queue' + AND + onid IN + ( + SELECT + id + FROM + crm_mailing_list_queue cmlq + WHERE message_id = crm_mailing_list_message.id + ) + AND + event_id > 0 + AND + sent IS NOT NULL + ) + AS last_sent + "); if (!empty($_REQUEST['_hide_system_emails'])) { $this->whereAddIn("!{$this->tableName()}.name", array('EVENT_ERRORS_REPORT'), 'string'); diff --git a/NotifySend.php b/NotifySend.php index b07a81c8..e32fc6cb 100644 --- a/NotifySend.php +++ b/NotifySend.php @@ -85,7 +85,7 @@ class Pman_Core_NotifySend extends Pman function get($id,$opts=array()) { - + //print_r($opts); if (!empty($opts['DB_DataObject-debug'])) { DB_DataObject::debugLevel($opts['DB_DataObject-debug']); @@ -101,6 +101,7 @@ class Pman_Core_NotifySend extends Pman if (!$w->get($id)) { $this->errorHandler("invalid id\n"); } + if (!$force && strtotime($w->act_when) < strtotime($w->sent)) { @@ -227,7 +228,7 @@ class Pman_Core_NotifySend extends Pman if ($email === false || isset($email['error']) || empty($p)) { // object returned 'false' - it does not know how to send it.. - $ev = $this->addEvent('NOTIFY', $w, isset($email['error']) ? + $ev = $this->addEvent('NOTIFYFAIL', $w, isset($email['error']) ? $email['error'] : "INTERNAL ERROR - We can not handle " . $w->ontable); $ww = clone($w); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent..... @@ -276,7 +277,7 @@ class Pman_Core_NotifySend extends Pman require_once 'Validate.php'; if (!Validate::email($p->email, true)) { - $ev = $this->addEvent('NOTIFY', $w, "INVALID ADDRESS: " . $p->email); + $ev = $this->addEvent('NOTIFYFAIL', $w, "INVALID ADDRESS: " . $p->email); $ww = clone($w); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent..... $w->msgid = ''; @@ -324,7 +325,7 @@ class Pman_Core_NotifySend extends Pman $this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED\n"); } - $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email ); + $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email ); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent..... $w->msgid = ''; $w->event_id = $ev->id; @@ -338,7 +339,7 @@ class Pman_Core_NotifySend extends Pman if (!$force && strtotime($w->act_start) < strtotime('NOW - 14 DAY')) { - $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - GIVE UP - ". $p->email ); + $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - GIVE UP - ". $p->email ); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent..... $w->msgid = ''; $w->event_id = $ev->id; @@ -531,7 +532,7 @@ class Pman_Core_NotifySend extends Pman $errmsg= $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext']; } - $ev = $this->addEvent('NOTIFY', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") . + $ev = $this->addEvent('NOTIFYFAIL', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") . $errmsg); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent..... $w->msgid = ''; @@ -543,7 +544,7 @@ class Pman_Core_NotifySend extends Pman // handle no host availalbe forever... if (strtotime($w->act_start) < strtotime('NOW - 3 DAYS')) { - $ev = $this->addEvent('NOTIFY', $w, "RETRY TIME EXCEEDED - ". $p->email); + $ev = $this->addEvent('NOTIFYFAIL', $w, "RETRY TIME EXCEEDED - ". $p->email); $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent..... $w->msgid = ''; $w->event_id = $ev->id; diff --git a/Pman.Dialog.CoreEmail.bjs b/Pman.Dialog.CoreEmail.bjs index 8b6d20a0..27736446 100644 --- a/Pman.Dialog.CoreEmail.bjs +++ b/Pman.Dialog.CoreEmail.bjs @@ -2,7 +2,7 @@ "name" : "Pman.Dialog.CoreEmail", "parent" : "", "title" : "", - "path" : "/home/alan/gitlive/Pman.Core/Pman.Dialog.CoreEmail.bjs", + "path" : "/home/leon/gitlive/web.MediaOutreach/Pman/Core/Pman.Dialog.CoreEmail.bjs", "permname" : "", "modOrder" : "001", "strings" : { @@ -80,14 +80,14 @@ "items" : [ { "xtype" : "LayoutRegion", - "tabPosition" : "top", "$ xns" : "Roo", + "tabPosition" : "top", "* prop" : "center" }, { "hidden" : true, - "title" : "Images / Attachments", "xtype" : "LayoutRegion", + "title" : "Images / Attachments", "width" : 500, "$ xns" : "Roo", "split" : true, @@ -96,8 +96,8 @@ }, { "autoScroll" : false, - "fitToFrame" : true, "region" : "center", + "fitToFrame" : true, "xtype" : "NestedLayoutPanel", "fitContainer" : true, "$ xns" : "Roo", @@ -198,8 +198,8 @@ "items" : [ { "$ url" : "baseURL + '/Core/MailTemplateList.php'", - "xtype" : "HttpProxy", "method" : "GET", + "xtype" : "HttpProxy", "$ xns" : "Roo.data", "* prop" : "proxy" }, @@ -247,8 +247,8 @@ "render" : "function (_self, width, height)\n{\n \n Roo.log(\"RESIZE, \" + width + ',' + height);\n \n var ew = Math.max(250, width-50);\n var eh = Math.max(250,height-50) ;\n \n \n\n}" }, "autoScroll" : false, - "background" : false, "fitToFrame" : true, + "background" : false, "region" : "center", "title" : "Message", "xtype" : "ContentPanel", @@ -358,8 +358,8 @@ "items" : [ { "$ url" : "baseURL + '/Roo/Core_group'", - "method" : "GET", "xtype" : "HttpProxy", + "method" : "GET", "$ xns" : "Roo.data", "* prop" : "proxy" }, @@ -393,8 +393,8 @@ "items" : [ { "hideLabels" : true, - "style" : "text-align:center;", "legend" : "Html Editor", + "style" : "text-align:center;", "xtype" : "FieldSet", "$ xns" : "Roo.form", "items" : [ @@ -404,8 +404,8 @@ "autosave" : "function (_self)\n{\n Roo.log('autosave');\n \n var id = _this.form.findField('id').getValue() * 1;\n \n /*\n if(!_self.editorcore.sourceEditMode){\n _self.syncValue();\n }else{\n _self.pushValue();\n }\n */\n \n new Pman.Request({\n url : baseURL + '/Roo/Events.php',\n method :'POST',\n params : {\n id : 0,\n action : 'AUTOSAVE',\n on_id : (id > 0) ? id : 0,\n on_table : 'crm_mailing_list_message',\n remarks : 'BODY',\n source: _self.getValue()\n },\n success : function() {\n _self.originalValue = _self.getValue();\n \n },\n failure : function() \n {\n Roo.log('body autosave failed?!');\n }\n });\n \n}" }, "bool allowComments" : true, - "| function autosave" : "function() {\n \n var body = _this.form.findField('bodytext');\n \n if(!body.wrap.isVisible(true) || body.getValue() == '' || !body.isDirty()){\n Roo.log('body not dirty');\n return;\n }\n \n Roo.log('body dirty, auto save!');\n \n body.fireEvent('autosave', body);\n \n}\n", "xtype" : "HtmlEditor", + "| function autosave" : "function() {\n \n var body = _this.form.findField('bodytext');\n \n if(!body.wrap.isVisible(true) || body.getValue() == '' || !body.isDirty()){\n Roo.log('body not dirty');\n return;\n }\n \n Roo.log('body dirty, auto save!');\n \n body.fireEvent('autosave', body);\n \n}\n", "$ cwhite" : "[ \n 'background',\n 'background-color',\n 'border',\n 'border-radius',\n 'border-bottom',\n 'border-left',\n 'border-right',\n 'border-top',\n 'border-collapse',\n 'border-color',\n 'border-style',\n 'border-width',\n\n \n 'box-shadow',\n 'clear',\n 'color',\n 'cursor',\n 'display',\n 'float' ,\n 'font-family',\n 'font-size',\n 'font-style', \n 'font-weight',\n\n 'height',\n 'left',\n 'line-height',\n 'list-style',\n 'margin',\n 'margin-bottom',\n 'margin-left',\n 'margin-right',\n 'margin-top',\n 'max-width',\n 'min-height',\n '-ms-interpolation-mode',\n 'mso-table-rspace',\n '-ms-text-size-adjust',\n 'outline',\n 'overflow',\n 'padding',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'position',\n 'right',\n 'text-align',\n 'text-decoration',\n 'top',\n 'vertical-align',\n '-webkit-text-size-adjust',\n 'width',\n 'width',\n 'z-index'\n ]", "boolean autoClean" : false, "$ xns" : "Roo.form", @@ -464,8 +464,8 @@ "items" : [ { "$ url" : "baseURL + '/Roo/Images.php'", - "method" : "GET", "xtype" : "HttpProxy", + "method" : "GET", "$ xns" : "Roo.data", "* prop" : "proxy" }, @@ -562,8 +562,8 @@ "items" : [ { "hideLabels" : true, - "style" : "text-align:center;", "legend" : "Plain Text", + "style" : "text-align:center;", "xtype" : "FieldSet", "$ xns" : "Roo.form", "items" : [ @@ -610,8 +610,8 @@ "|activate" : "function() {\n _this.ipanel = this;\n if (_this.igrid) {\n _this.igrid.ds.load({});\n }\n}" }, "autoScroll" : false, - "background" : false, "fitToframe" : true, + "background" : false, "region" : "east", "title" : "Images / Attachments", "xtype" : "GridPanel", @@ -641,8 +641,8 @@ "items" : [ { "$ url" : "baseURL + '/Roo/Images.php'", - "method" : "GET", "xtype" : "HttpProxy", + "method" : "GET", "$ xns" : "Roo.data", "* prop" : "proxy" }, @@ -686,8 +686,8 @@ }, { "xtype" : "ColumnModel", - "header" : "Filename", "width" : 300, + "header" : "Filename", "$ renderer" : "function(v,x,r)\n{\n var width = r.data.width;\n var height = r.data.height;\n \n if(width > 50){\n height = Math.round(height * 50 / width);\n width = 50;\n }\n \n return '';\n}", "$ xns" : "Roo.grid", "* prop" : "colModel[]", @@ -695,8 +695,8 @@ }, { "xtype" : "ColumnModel", - "width" : 75, "header" : "Displayorder", + "width" : 75, "$ renderer" : "function(v) { return String.format('{0}', v); }", "$ xns" : "Roo.grid", "* prop" : "colModel[]", @@ -704,8 +704,8 @@ }, { "xtype" : "ColumnModel", - "header" : "Title", "width" : 75, + "header" : "Title", "$ renderer" : "function(v) { return String.format('{0}', v); }", "$ xns" : "Roo.grid", "* prop" : "colModel[]", @@ -756,4 +756,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/Pman.Dialog.CoreEmail.js b/Pman.Dialog.CoreEmail.js index 7480415a..1ef1e300 100644 --- a/Pman.Dialog.CoreEmail.js +++ b/Pman.Dialog.CoreEmail.js @@ -76,7 +76,7 @@ Pman.Dialog.CoreEmail = { this.callback = cb; this.data = data; - this.dialog.show.apply(this.dialog, Array.prototype.slice.call(arguments).slice(2)); + this.dialog.show(this.data._el); if (this.form) { this.form.reset(); this.form.setValues(data); -- 2.39.2