1
|
|
|
<?php |
2
|
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
3
|
|
|
/********************************************************************************* |
4
|
|
|
* SugarCRM Community Edition is a customer relationship management program developed by |
5
|
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
6
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
20
|
|
|
* details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25
|
|
|
* 02110-1301 USA. |
26
|
|
|
* |
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
29
|
|
|
* |
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
33
|
|
|
* |
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
39
|
|
|
********************************************************************************/ |
40
|
|
|
|
41
|
|
|
/********************************************************************************* |
42
|
|
|
|
43
|
|
|
* Description: Defines the English language pack for the base application. |
44
|
|
|
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
45
|
|
|
* All Rights Reserved. |
46
|
|
|
* Contributor(s): ______________________________________.. |
47
|
|
|
********************************************************************************/ |
48
|
|
|
|
49
|
|
|
/* |
50
|
|
|
*returns a list of objects a message can be scoped by, the list contacts the current campaign |
51
|
|
|
*name and list of all prospects associated with this campaign.. |
52
|
|
|
* |
53
|
|
|
*/ |
54
|
|
|
function get_message_scope_dom($campaign_id, $campaign_name,$db=null, $mod_strings=array()) { |
55
|
|
|
|
56
|
|
|
if (empty($db)) { |
57
|
|
|
$db = DBManagerFactory::getInstance(); |
58
|
|
|
} |
59
|
|
|
if (empty($mod_strings) or !isset($mod_strings['LBL_DEFAULT'])) { |
60
|
|
|
global $current_language; |
61
|
|
|
$mod_strings = return_module_language($current_language, 'Campaigns'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
//find prospect list attached to this campaign.. |
65
|
|
|
$query = "SELECT prospect_list_id, prospect_lists.name "; |
66
|
|
|
$query .= "FROM prospect_list_campaigns "; |
67
|
|
|
$query .= "INNER join prospect_lists on prospect_lists.id = prospect_list_campaigns.prospect_list_id "; |
68
|
|
|
$query .= "WHERE prospect_lists.deleted = 0 "; |
69
|
|
|
$query .= "AND prospect_list_campaigns.deleted=0 "; |
70
|
|
|
$query .= "AND campaign_id='". $db->quote($campaign_id)."'"; |
71
|
|
|
$query.=" and prospect_lists.list_type not like 'exempt%'"; |
72
|
|
|
|
73
|
|
|
//add campaign to the result array. |
74
|
|
|
//$return_array[$campaign_id]= $campaign_name . ' (' . $mod_strings['LBL_DEFAULT'] . ')'; |
75
|
|
|
|
76
|
|
|
$result=$db->query($query); |
77
|
|
|
while(($row=$db->fetchByAssoc($result))!= null) { |
78
|
|
|
$return_array[$row['prospect_list_id']]=$row['name']; |
79
|
|
|
} |
80
|
|
|
if (empty($return_array)) $return_array=array(); |
81
|
|
|
else return $return_array; |
82
|
|
|
} |
83
|
|
|
/** |
84
|
|
|
* Return bounce handling mailboxes for campaign. |
85
|
|
|
* |
86
|
|
|
* @param unknown_type $emails |
87
|
|
|
* @param unknown_type $get_box_name, Set it to false if want to get "From Name" other than the InboundEmail Name. |
|
|
|
|
88
|
|
|
* @return $get_name=true, bounce handling mailboxes' name; $get_name=false, bounce handling mailboxes' from name. |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
function get_campaign_mailboxes(&$emails, $get_name=true) { |
91
|
|
|
if (!class_exists('InboundEmail')) { |
92
|
|
|
require('modules/InboundEmail/InboundEmail.php'); |
93
|
|
|
} |
94
|
|
|
$query = "select id,name,stored_options from inbound_email where mailbox_type='bounce' and status='Active' and deleted='0'"; |
95
|
|
|
$db = DBManagerFactory::getInstance(); |
96
|
|
|
$result=$db->query($query); |
97
|
|
|
while(($row=$db->fetchByAssoc($result))!= null) { |
98
|
|
|
if($get_name) { |
99
|
|
|
$return_array[$row['id']] = $row['name']; |
100
|
|
|
} else { |
101
|
|
|
$return_array[$row['id']]= InboundEmail::get_stored_options_static('from_name',$row['name'],$row['stored_options']); |
102
|
|
|
} |
103
|
|
|
$emails[$row['id']]=InboundEmail::get_stored_options_static('from_addr','[email protected]',$row['stored_options']); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (empty($return_array)) $return_array=array(''=>''); |
107
|
|
|
return $return_array; |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
function get_campaign_mailboxes_with_stored_options() { |
112
|
|
|
$ret = array(); |
113
|
|
|
|
114
|
|
|
if(!class_exists('InboundEmail')) { |
115
|
|
|
require('modules/InboundEmail/InboundEmail.php'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$q = "SELECT id, name, stored_options FROM inbound_email WHERE mailbox_type='bounce' AND status='Active' AND deleted='0'"; |
119
|
|
|
|
120
|
|
|
$db = DBManagerFactory::getInstance(); |
121
|
|
|
|
122
|
|
|
$r = $db->query($q); |
123
|
|
|
|
124
|
|
|
while($a = $db->fetchByAssoc($r)) { |
125
|
|
|
$ret[$a['id']] = unserialize(base64_decode($a['stored_options'])); |
126
|
|
|
} |
127
|
|
|
return $ret; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
function log_campaign_activity($identifier, $activity, $update=true, $clicked_url_key=null) { |
131
|
|
|
|
132
|
|
|
$return_array = array(); |
133
|
|
|
|
134
|
|
|
$db = DBManagerFactory::getInstance(); |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
|
138
|
|
|
//check to see if the identifier has been replaced with Banner string |
139
|
|
|
if($identifier == 'BANNER' && isset($clicked_url_key) && !empty($clicked_url_key)) |
140
|
|
|
{ |
141
|
|
|
// create md5 encrypted string using the client ip, this will be used for tracker id purposes |
142
|
|
|
$enc_id = 'BNR'.md5($_SERVER['REMOTE_ADDR']); |
143
|
|
|
|
144
|
|
|
//default the identifier to ip address |
145
|
|
|
$identifier = $enc_id; |
146
|
|
|
|
147
|
|
|
//if user has chosen to not use this mode of id generation, then replace identifier with plain guid. |
148
|
|
|
//difference is that guid will generate a new campaign log for EACH CLICK!! |
149
|
|
|
//encrypted generation will generate 1 campaign log and update the hit counter for each click |
150
|
|
|
if(isset($sugar_config['campaign_banner_id_generation']) && $sugar_config['campaign_banner_id_generation'] != 'md5'){ |
|
|
|
|
151
|
|
|
$identifier = create_guid(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
//retrieve campaign log. |
155
|
|
|
$trkr_query = "select * from campaign_log where target_tracker_key='$identifier' and related_id = '$clicked_url_key'"; |
156
|
|
|
$current_trkr=$db->query($trkr_query); |
157
|
|
|
$row=$db->fetchByAssoc($current_trkr); |
158
|
|
|
|
159
|
|
|
//if campaign log is not retrieved (this is a new ip address or we have chosen to create |
160
|
|
|
//unique entries for each click |
161
|
|
|
if($row==null || empty($row)){ |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
//retrieve campaign id |
165
|
|
|
$trkr_query = "select ct.campaign_id from campaign_trkrs ct, campaigns c where c.id = ct.campaign_id and ct.id = '$clicked_url_key'"; |
166
|
|
|
$current_trkr=$db->query($trkr_query); |
167
|
|
|
$row=$db->fetchByAssoc($current_trkr); |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
//create new campaign log with minimal info. Note that we are creating new unique id |
171
|
|
|
//as target id, since we do not link banner/web campaigns to any users |
172
|
|
|
|
173
|
|
|
$data['target_id']="'" . create_guid() . "'"; |
174
|
|
|
$data['target_type']= "'Prospects'"; |
175
|
|
|
$data['id']="'" . create_guid() . "'"; |
176
|
|
|
$data['campaign_id']="'" . $row['campaign_id'] . "'"; |
177
|
|
|
$data['target_tracker_key']="'" . $identifier . "'"; |
178
|
|
|
$data['activity_type']="'" . $activity . "'"; |
179
|
|
|
$data['activity_date']="'" . TimeDate::getInstance()->nowDb() . "'"; |
180
|
|
|
$data['hits']=1; |
181
|
|
|
$data['deleted']=0; |
182
|
|
|
if (!empty($clicked_url_key)) { |
183
|
|
|
$data['related_id']="'".$clicked_url_key."'"; |
184
|
|
|
$data['related_type']="'".'CampaignTrackers'."'"; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
//values for return array.. |
188
|
|
|
$return_array['target_id']=$data['target_id']; |
189
|
|
|
$return_array['target_type']=$data['target_type']; |
190
|
|
|
|
191
|
|
|
//create insert query for new campaign log |
192
|
|
|
$insert_query="INSERT into campaign_log (" . implode(",",array_keys($data)) . ")"; |
193
|
|
|
$insert_query.=" VALUES (" . implode(",",array_values($data)) . ")"; |
194
|
|
|
$db->query($insert_query); |
195
|
|
|
}else{ |
196
|
|
|
|
197
|
|
|
//campaign log already exists, so just set the return array and update hits column |
198
|
|
|
$return_array['target_id']= $row['target_id']; |
199
|
|
|
$return_array['target_type']= $row['target_type']; |
200
|
|
|
$query1="update campaign_log set hits=hits+1 where id='{$row['id']}'"; |
201
|
|
|
$current=$db->query($query1); |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
//return array and exit |
207
|
|
|
return $return_array; |
208
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
|
213
|
|
|
$query1="select * from campaign_log where target_tracker_key='$identifier' and activity_type='$activity'"; |
214
|
|
|
if (!empty($clicked_url_key)) { |
215
|
|
|
$query1.=" AND related_id='$clicked_url_key'"; |
216
|
|
|
} |
217
|
|
|
$current=$db->query($query1); |
218
|
|
|
$row=$db->fetchByAssoc($current); |
219
|
|
|
|
220
|
|
|
if ($row==null) { |
221
|
|
|
$query="select * from campaign_log where target_tracker_key='$identifier' and activity_type='targeted'"; |
222
|
|
|
$targeted=$db->query($query); |
223
|
|
|
$row=$db->fetchByAssoc($targeted); |
224
|
|
|
|
225
|
|
|
//if activity is removed and target type is users, then a user is trying to opt out |
226
|
|
|
//of emails. This is not possible as Users Table does not have opt out column. |
227
|
|
|
if ($row && (strtolower($row['target_type']) == 'users' && $activity == 'removed' )) { |
228
|
|
|
$return_array['target_id']= $row['target_id']; |
229
|
|
|
$return_array['target_type']= $row['target_type']; |
230
|
|
|
return $return_array; |
231
|
|
|
} |
232
|
|
|
elseif ($row){ |
233
|
|
|
$data['id']="'" . create_guid() . "'"; |
234
|
|
|
$data['campaign_id']="'" . $row['campaign_id'] . "'"; |
235
|
|
|
$data['target_tracker_key']="'" . $identifier . "'"; |
236
|
|
|
$data['target_id']="'" . $row['target_id'] . "'"; |
237
|
|
|
$data['target_type']="'" . $row['target_type'] . "'"; |
238
|
|
|
$data['activity_type']="'" . $activity . "'"; |
239
|
|
|
$data['activity_date']="'" . TimeDate::getInstance()->nowDb() . "'"; |
240
|
|
|
$data['list_id']="'" . $row['list_id'] . "'"; |
241
|
|
|
$data['marketing_id']="'" . $row['marketing_id'] . "'"; |
242
|
|
|
$data['hits']=1; |
243
|
|
|
$data['deleted']=0; |
244
|
|
|
if (!empty($clicked_url_key)) { |
245
|
|
|
$data['related_id']="'".$clicked_url_key."'"; |
246
|
|
|
$data['related_type']="'".'CampaignTrackers'."'"; |
247
|
|
|
} |
248
|
|
|
//values for return array.. |
249
|
|
|
$return_array['target_id']=$row['target_id']; |
250
|
|
|
$return_array['target_type']=$row['target_type']; |
251
|
|
|
$insert_query="INSERT into campaign_log (" . implode(",",array_keys($data)) . ")"; |
252
|
|
|
$insert_query.=" VALUES (" . implode(",",array_values($data)) . ")"; |
253
|
|
|
$db->query($insert_query); |
254
|
|
|
} |
255
|
|
|
} else { |
256
|
|
|
|
257
|
|
|
$return_array['target_id']= $row['target_id']; |
258
|
|
|
$return_array['target_type']= $row['target_type']; |
259
|
|
|
|
260
|
|
|
$query1="update campaign_log set hits=hits+1 where id='{$row['id']}'"; |
261
|
|
|
$current=$db->query($query1); |
262
|
|
|
|
263
|
|
|
} |
264
|
|
|
//check to see if this is a removal action |
265
|
|
|
if ($row && $activity == 'removed' ) { |
266
|
|
|
//retrieve campaign and check it's type, we are looking for newsletter Campaigns |
267
|
|
|
$query = "SELECT campaigns.* FROM campaigns WHERE campaigns.id = '".$row['campaign_id']."' "; |
268
|
|
|
$result = $db->query($query); |
269
|
|
|
if(!empty($result)) |
270
|
|
|
{ |
271
|
|
|
$c_row = $db->fetchByAssoc($result); |
272
|
|
|
|
273
|
|
|
//if type is newsletter, then add campaign id to return_array for further processing. |
274
|
|
|
if(isset($c_row['campaign_type']) && $c_row['campaign_type'] == 'NewsLetter'){ |
275
|
|
|
$return_array['campaign_id']=$c_row['id']; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
return $return_array; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* |
285
|
|
|
* This method is deprecated |
286
|
|
|
* @deprecated 62_Joneses - June 24, 2011 |
287
|
|
|
* @see campaign_log_lead_or_contact_entry() |
288
|
|
|
*/ |
289
|
|
|
function campaign_log_lead_entry($campaign_id, $parent_bean,$child_bean,$activity_type){ |
290
|
|
|
campaign_log_lead_or_contact_entry($campaign_id, $parent_bean,$child_bean,$activity_type); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
|
294
|
|
|
function campaign_log_lead_or_contact_entry($campaign_id, $parent_bean,$child_bean,$activity_type){ |
295
|
|
|
global $timedate; |
296
|
|
|
|
297
|
|
|
//create campaign tracker id and retrieve related bio bean |
298
|
|
|
$tracker_id = create_guid(); |
299
|
|
|
//create new campaign log record. |
300
|
|
|
$campaign_log = new CampaignLog(); |
301
|
|
|
$campaign_log->campaign_id = $campaign_id; |
302
|
|
|
$campaign_log->target_tracker_key = $tracker_id; |
303
|
|
|
$campaign_log->related_id = $parent_bean->id; |
304
|
|
|
$campaign_log->related_type = $parent_bean->module_dir; |
305
|
|
|
$campaign_log->target_id = $child_bean->id; |
306
|
|
|
$campaign_log->target_type = $child_bean->module_dir; |
307
|
|
|
$campaign_log->activity_date = $timedate->now(); |
308
|
|
|
$campaign_log->activity_type = $activity_type; |
309
|
|
|
//save the campaign log entry |
310
|
|
|
$campaign_log->save(); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
|
314
|
|
|
function get_campaign_urls($campaign_id) { |
315
|
|
|
$return_array=array(); |
316
|
|
|
|
317
|
|
|
if (!empty($campaign_id)) { |
318
|
|
|
|
319
|
|
|
$db = DBManagerFactory::getInstance(); |
320
|
|
|
|
321
|
|
|
$campaign_id = $db->quote($campaign_id); |
322
|
|
|
|
323
|
|
|
$query1="select * from campaign_trkrs where campaign_id='$campaign_id' and deleted=0"; |
324
|
|
|
$current=$db->query($query1); |
325
|
|
|
while (($row=$db->fetchByAssoc($current)) != null) { |
326
|
|
|
$return_array['{'.$row['tracker_name'].'}']=$row['tracker_name'] . ' : ' . $row['tracker_url']; |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
return $return_array; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Queries for the list |
334
|
|
|
*/ |
335
|
|
|
function get_subscription_lists_query($focus, $additional_fields = null) { |
336
|
|
|
//get all prospect lists belonging to Campaigns of type newsletter |
337
|
|
|
$all_news_type_pl_query = "select c.name, pl.list_type, plc.campaign_id, plc.prospect_list_id"; |
338
|
|
|
if(is_array($additional_fields) && !empty($additional_fields)) $all_news_type_pl_query .= ', ' . implode(', ', $additional_fields); |
339
|
|
|
$all_news_type_pl_query .= " from prospect_list_campaigns plc , prospect_lists pl, campaigns c "; |
340
|
|
|
|
341
|
|
|
|
342
|
|
|
$all_news_type_pl_query .= "where plc.campaign_id = c.id "; |
343
|
|
|
$all_news_type_pl_query .= "and plc.prospect_list_id = pl.id "; |
344
|
|
|
$all_news_type_pl_query .= "and c.campaign_type = 'NewsLetter' and pl.deleted = 0 and c.deleted=0 and plc.deleted=0 "; |
345
|
|
|
$all_news_type_pl_query .= "and (pl.list_type like 'exempt%' or pl.list_type ='default') "; |
346
|
|
|
|
347
|
|
|
/* BEGIN - SECURITY GROUPS */ |
348
|
|
|
if($focus->bean_implements('ACL') && ACLController::requireSecurityGroup('Campaigns', 'list') ) |
349
|
|
|
{ |
350
|
|
|
require_once('modules/SecurityGroups/SecurityGroup.php'); |
351
|
|
|
global $current_user; |
352
|
|
|
$owner_where = $focus->getOwnerWhere($current_user->id); |
353
|
|
|
$group_where = SecurityGroup::getGroupWhere('c','Campaigns',$current_user->id); |
354
|
|
|
$all_news_type_pl_query .= " AND ( c.assigned_user_id ='".$current_user->id."' or ".$group_where.") "; |
355
|
|
|
} |
356
|
|
|
/* END - SECURITY GROUPS */ |
357
|
|
|
|
358
|
|
|
$all_news_type_list =$focus->db->query($all_news_type_pl_query); |
359
|
|
|
|
360
|
|
|
//build array of all newsletter campaigns |
361
|
|
|
$news_type_list_arr = array(); |
362
|
|
|
while ($row = $focus->db->fetchByAssoc($all_news_type_list)){$news_type_list_arr[] = $row;} |
363
|
|
|
|
364
|
|
|
//now get all the campaigns that the current user is assigned to |
365
|
|
|
$all_plp_current = "select prospect_list_id from prospect_lists_prospects where related_id = '$focus->id' and deleted = 0 "; |
366
|
|
|
|
367
|
|
|
//build array of prospect lists that this user belongs to |
368
|
|
|
$current_plp =$focus->db->query($all_plp_current ); |
369
|
|
|
$current_plp_arr = array(); |
370
|
|
|
while ($row = $focus->db->fetchByAssoc($current_plp)){$current_plp_arr[] = $row;} |
371
|
|
|
|
372
|
|
|
return array('current_plp_arr' => $current_plp_arr, 'news_type_list_arr' => $news_type_list_arr); |
373
|
|
|
} |
374
|
|
|
/* |
375
|
|
|
* This function takes in a bean from a lead, prospect, or contact and returns an array containing |
376
|
|
|
* all subscription lists that the bean is a part of, and all the subscriptions that the bean is not |
377
|
|
|
* a part of. The array elements have the key names of "subscribed" and "unsusbscribed". These elements contain an array |
378
|
|
|
* of the corresponding list. In other words, the "subscribed" element holds another array that holds the subscription information. |
379
|
|
|
* |
380
|
|
|
* The subscription information is a concatenated string that holds the prospect list id and the campaign id, separated by at "@" character. |
381
|
|
|
* To parse these information string into something more usable, use the "process subscriptions()" function |
382
|
|
|
* |
383
|
|
|
* */ |
384
|
|
|
function get_subscription_lists($focus, $descriptions = false) { |
385
|
|
|
$subs_arr = array(); |
386
|
|
|
$unsubs_arr = array(); |
387
|
|
|
|
388
|
|
|
$results = get_subscription_lists_query($focus, $descriptions); |
389
|
|
|
|
390
|
|
|
$news_type_list_arr = $results['news_type_list_arr']; |
391
|
|
|
$current_plp_arr = $results['current_plp_arr']; |
392
|
|
|
|
393
|
|
|
//For each prospect list of type 'NewsLetter', check to see if current user is already in list, |
394
|
|
|
foreach($news_type_list_arr as $news_list){ |
395
|
|
|
$match = 'false'; |
396
|
|
|
|
397
|
|
|
//perform this check against each prospect list this user belongs to |
398
|
|
|
foreach($current_plp_arr as $current_list_key => $current_list){//echo " new entry from current lists user is subscribed to-------------"; |
399
|
|
|
//compare current user list id against newsletter id |
400
|
|
|
if ($news_list['prospect_list_id'] == $current_list['prospect_list_id']){ |
401
|
|
|
//if id's match, user is subscribed to this list, check to see if this is an exempt list, |
402
|
|
|
if(strpos($news_list['list_type'], 'exempt')!== false){ |
403
|
|
|
//this is an exempt list, so process |
404
|
|
|
if(array_key_exists($news_list['name'],$subs_arr)){ |
405
|
|
|
//first, add to unsubscribed array |
406
|
|
|
$unsubs_arr[$news_list['name']] = $subs_arr[$news_list['name']]; |
407
|
|
|
//now remove from exempt subscription list |
408
|
|
|
unset($subs_arr[$news_list['name']]); |
409
|
|
|
}else{ |
410
|
|
|
//we know this is an exempt list the user belongs to, but the |
411
|
|
|
//non exempt list has not been processed yet, so just add to exempt array |
412
|
|
|
$unsubs_arr[$news_list['name']] = "prospect_list@".$news_list['prospect_list_id']."@campaign@".$news_list['campaign_id']; |
413
|
|
|
} |
414
|
|
|
$match = 'false';//although match is false, this is an exempt array, so |
415
|
|
|
//it will not be added a second time down below |
416
|
|
|
}else{ |
417
|
|
|
//this list is not exempt, and user is subscribed, so add to subscribed array, and unset from the unsubs_arr |
418
|
|
|
//as long as this list is not in exempt array |
419
|
|
|
$temp = "prospect_list@".$news_list['prospect_list_id']."@campaign@".$news_list['campaign_id']; |
420
|
|
|
if(!array_search($temp,$unsubs_arr)){ |
421
|
|
|
$subs_arr[$news_list['name']] = "prospect_list@".$news_list['prospect_list_id']."@campaign@".$news_list['campaign_id']; |
422
|
|
|
$match = 'true'; |
423
|
|
|
unset($unsubs_arr[$news_list['name']]); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
}else{ |
|
|
|
|
427
|
|
|
//do nothing, there is no match |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
//if this newsletter id never matched a user subscription.. |
431
|
|
|
//..then add to available(unsubscribed) NewsLetters if list is not of type exempt |
432
|
|
|
if (($match == 'false') && (strpos($news_list['list_type'], 'exempt') === false) && (!array_key_exists($news_list['name'], $subs_arr))) |
433
|
|
|
{ |
434
|
|
|
$unsubs_arr[$news_list['name']] = "prospect_list@".$news_list['prospect_list_id']."@campaign@".$news_list['campaign_id']; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
} |
438
|
|
|
$return_array['unsubscribed'] = $unsubs_arr; |
439
|
|
|
$return_array['subscribed'] = $subs_arr; |
440
|
|
|
return $return_array; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* same function as get_subscription_lists, but with the data separated in an associated array |
445
|
|
|
*/ |
446
|
|
|
function get_subscription_lists_keyed($focus) { |
447
|
|
|
$subs_arr = array(); |
448
|
|
|
$unsubs_arr = array(); |
449
|
|
|
|
450
|
|
|
$results = get_subscription_lists_query($focus, array('c.content', 'c.frequency')); |
451
|
|
|
|
452
|
|
|
$news_type_list_arr = $results['news_type_list_arr']; |
453
|
|
|
$current_plp_arr = $results['current_plp_arr']; |
454
|
|
|
|
455
|
|
|
//For each prospect list of type 'NewsLetter', check to see if current user is already in list, |
456
|
|
|
foreach($news_type_list_arr as $news_list){ |
457
|
|
|
$match = false; |
458
|
|
|
|
459
|
|
|
$news_list_data = array('prospect_list_id' => $news_list['prospect_list_id'], |
460
|
|
|
'campaign_id' => $news_list['campaign_id'], |
461
|
|
|
'description' => $news_list['content'], |
462
|
|
|
'frequency' => $news_list['frequency']); |
463
|
|
|
|
464
|
|
|
//perform this check against each prospect list this user belongs to |
465
|
|
|
foreach($current_plp_arr as $current_list_key => $current_list){//echo " new entry from current lists user is subscribed to-------------"; |
466
|
|
|
//compare current user list id against newsletter id |
467
|
|
|
if ($news_list['prospect_list_id'] == $current_list['prospect_list_id']){ |
468
|
|
|
//if id's match, user is subscribed to this list, check to see if this is an exempt list, |
469
|
|
|
|
470
|
|
|
if($news_list['list_type'] == 'exempt'){ |
471
|
|
|
//this is an exempt list, so process |
472
|
|
|
if(array_key_exists($news_list['name'],$subs_arr)){ |
473
|
|
|
//first, add to unsubscribed array |
474
|
|
|
$unsubs_arr[$news_list['name']] = $subs_arr[$news_list['name']]; |
475
|
|
|
//now remove from exempt subscription list |
476
|
|
|
unset($subs_arr[$news_list['name']]); |
477
|
|
|
}else{ |
478
|
|
|
//we know this is an exempt list the user belongs to, but the |
479
|
|
|
//non exempt list has not been processed yet, so just add to exempt array |
480
|
|
|
$unsubs_arr[$news_list['name']] = $news_list_data; |
481
|
|
|
} |
482
|
|
|
$match = false;//although match is false, this is an exempt array, so |
483
|
|
|
//it will not be added a second time down below |
484
|
|
|
}else{ |
485
|
|
|
//this list is not exempt, and user is subscribed, so add to subscribed array |
486
|
|
|
//as long as this list is not in exempt array |
487
|
|
|
if(!array_key_exists($news_list['name'],$unsubs_arr)){ |
488
|
|
|
$subs_arr[$news_list['name']] = $news_list_data; |
489
|
|
|
$match = 'true'; |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
}else{ |
|
|
|
|
493
|
|
|
//do nothing, there is no match |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
//if this newsletter id never matched a user subscription.. |
497
|
|
|
//..then add to available(unsubscribed) NewsLetters if list is not of type exempt |
498
|
|
|
if(($match == false) && ($news_list['list_type'] != 'exempt')){ |
|
|
|
|
499
|
|
|
$unsubs_arr[$news_list['name']] = $news_list_data; |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
$return_array['unsubscribed'] = $unsubs_arr; |
505
|
|
|
$return_array['subscribed'] = $subs_arr; |
506
|
|
|
return $return_array; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
|
510
|
|
|
|
511
|
|
|
/* |
512
|
|
|
* This function will take an array of strings that have been created by the "get_subscription_lists()" method |
513
|
|
|
* and parses it into an array. The returned array has it's key's labeled in a specific fashion. |
514
|
|
|
* |
515
|
|
|
* Each string produces a campaign and a prospect id. The keys are appended with a number specifying the order |
516
|
|
|
* it was process in. So an input array containing 3 strings will have the following key values: |
517
|
|
|
* "prospect_list0", "campaign0" |
518
|
|
|
* "prospect_list1", "campaign1" |
519
|
|
|
* "prospect_list2", "campaign2" |
520
|
|
|
* |
521
|
|
|
* */ |
522
|
|
|
function process_subscriptions($subscription_string_to_parse) { |
523
|
|
|
$subs_change = array(); |
524
|
|
|
|
525
|
|
|
//parse through and build list of id's'. We are retrieving the campaign_id and |
526
|
|
|
//the prospect_list id from the selected subscriptions |
527
|
|
|
$i = 0; |
528
|
|
|
foreach($subscription_string_to_parse as $subs_changes){ |
529
|
|
|
$subs_changes = trim($subs_changes); |
530
|
|
|
if(!empty($subs_changes)){ |
531
|
|
|
$ids_arr = explode("@", $subs_changes); |
532
|
|
|
$subs_change[$ids_arr[0].$i] = $ids_arr[1]; |
533
|
|
|
$subs_change[$ids_arr[2].$i] = $ids_arr[3]; |
534
|
|
|
$i = $i+1; |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
return $subs_change; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
|
541
|
|
|
/*This function is used by the Manage Subscriptions page in order to add the user |
542
|
|
|
* to the default prospect lists of the passed in campaign |
543
|
|
|
* Takes in campaign and prospect list id's we are subscribing to. |
544
|
|
|
* It also takes in a bean of the user (lead,target,prospect) we are subscribing |
545
|
|
|
* */ |
546
|
|
|
function subscribe($campaign, $prospect_list, $focus, $default_list = false) { |
547
|
|
|
$relationship = strtolower($focus->getObjectName()).'s'; |
548
|
|
|
|
549
|
|
|
//--grab all the lists for the passed in campaign id |
550
|
|
|
$pl_qry ="select id, list_type from prospect_lists where id in (select prospect_list_id from prospect_list_campaigns "; |
551
|
|
|
$pl_qry .= "where campaign_id = '$campaign') and deleted = 0 "; |
552
|
|
|
$GLOBALS['log']->debug("In Campaigns Util: subscribe function, about to run query: ".$pl_qry ); |
553
|
|
|
$pl_qry_result = $focus->db->query($pl_qry); |
554
|
|
|
|
555
|
|
|
//build the array of all prospect_lists |
556
|
|
|
$pl_arr = array(); |
557
|
|
|
while ($row = $focus->db->fetchByAssoc($pl_qry_result)){$pl_arr[] = $row;} |
558
|
|
|
|
559
|
|
|
//--grab all the prospect_lists this user belongs to |
560
|
|
|
$curr_pl_qry ="select prospect_list_id, related_id from prospect_lists_prospects "; |
561
|
|
|
$curr_pl_qry .="where related_id = '$focus->id' and deleted = 0 "; |
562
|
|
|
$GLOBALS['log']->debug("In Campaigns Util: subscribe function, about to run query: ".$curr_pl_qry ); |
563
|
|
|
$curr_pl_qry_result = $focus->db->query($curr_pl_qry); |
564
|
|
|
|
565
|
|
|
//build the array of all prospect lists that this current user belongs to |
566
|
|
|
$curr_pl_arr = array(); |
567
|
|
|
while ($row = $focus->db->fetchByAssoc($curr_pl_qry_result)){$curr_pl_arr[] = $row;} |
568
|
|
|
|
569
|
|
|
//search through prospect lists for this campaign and identifiy the "unsubscription list" |
570
|
|
|
$exempt_id = ''; |
571
|
|
|
foreach($pl_arr as $subscription_list){ |
572
|
|
|
if(strpos($subscription_list['list_type'], 'exempt')!== false){ |
573
|
|
|
$exempt_id = $subscription_list['id']; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
if($subscription_list['list_type'] == 'default' && $default_list) { |
577
|
|
|
$prospect_list = $subscription_list['id']; |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
//now that we have exempt (unsubscription) list id, compare against user list id's |
582
|
|
|
if(!empty($exempt_id)){ |
583
|
|
|
$exempt_array['exempt_id'] = $exempt_id; |
584
|
|
|
|
585
|
|
|
foreach($curr_pl_arr as $curr_subscription_list){ |
586
|
|
|
if($curr_subscription_list['prospect_list_id'] == $exempt_id){ |
587
|
|
|
//--if we are in here then user is subscribing to a list in which they are exempt. |
588
|
|
|
// we need to remove the user from this unsubscription list. |
589
|
|
|
//Begin by retrieving unsubscription prospect list |
590
|
|
|
$exempt_subscription_list = new ProspectList(); |
591
|
|
|
|
592
|
|
|
|
593
|
|
|
$exempt_result = $exempt_subscription_list->retrieve($exempt_id); |
594
|
|
|
if($exempt_result == null) |
595
|
|
|
{//error happened while retrieving this list |
596
|
|
|
return; |
597
|
|
|
} |
598
|
|
|
//load realationships and delete user from unsubscription list |
599
|
|
|
$exempt_subscription_list->load_relationship($relationship); |
600
|
|
|
$exempt_subscription_list->$relationship->delete($exempt_id,$focus->id); |
601
|
|
|
|
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
//Now we need to check if user is already in subscription list |
607
|
|
|
$already_here = 'false'; |
608
|
|
|
//for each list user is subscribed to, compare id's with current list id' |
609
|
|
|
foreach($curr_pl_arr as $user_list){ |
610
|
|
|
if(in_array($prospect_list, $user_list)){ |
611
|
|
|
//if user already exists, then set flag to true |
612
|
|
|
$already_here = 'true'; |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
if($already_here ==='true'){ |
|
|
|
|
616
|
|
|
//do nothing, user is already subscribed |
617
|
|
|
}else{ |
618
|
|
|
//user is not subscribed already, so add to subscription list |
619
|
|
|
$subscription_list = new ProspectList(); |
620
|
|
|
$subs_result = $subscription_list->retrieve($prospect_list); |
621
|
|
|
if($subs_result == null) |
622
|
|
|
{//error happened while retrieving this list, iterate and continue |
623
|
|
|
return; |
624
|
|
|
} |
625
|
|
|
//load subscription list and add this user |
626
|
|
|
$GLOBALS['log']->debug("In Campaigns Util, loading relationship: ".$relationship); |
627
|
|
|
$subscription_list->load_relationship($relationship); |
628
|
|
|
$subscription_list->$relationship->add($focus->id); |
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
|
633
|
|
|
/*This function is used by the Manage Subscriptions page in order to add the user |
634
|
|
|
* to the exempt prospect lists of the passed in campaign |
635
|
|
|
* Takes in campaign and focus parameters. |
636
|
|
|
* */ |
637
|
|
|
function unsubscribe($campaign, $focus) { |
638
|
|
|
$relationship = strtolower($focus->getObjectName()).'s'; |
639
|
|
|
//--grab all the list for this campaign id |
640
|
|
|
$pl_qry ="select id, list_type from prospect_lists where id in (select prospect_list_id from prospect_list_campaigns "; |
641
|
|
|
$pl_qry .= "where campaign_id = '$campaign') and deleted = 0 "; |
642
|
|
|
$pl_qry_result = $focus->db->query($pl_qry); |
643
|
|
|
//build the array with list information |
644
|
|
|
$pl_arr = array(); |
645
|
|
|
$GLOBALS['log']->debug("In Campaigns Util, about to run query: ".$pl_qry); |
646
|
|
|
while ($row = $focus->db->fetchByAssoc($pl_qry_result)){$pl_arr[] = $row;} |
647
|
|
|
|
648
|
|
|
//retrieve lists that this user belongs to |
649
|
|
|
$curr_pl_qry ="select prospect_list_id, related_id from prospect_lists_prospects "; |
650
|
|
|
$curr_pl_qry .="where related_id = '$focus->id' and deleted = 0 "; |
651
|
|
|
$GLOBALS['log']->debug("In Campaigns Util, unsubscribe function about to run query: ".$curr_pl_qry ); |
652
|
|
|
$curr_pl_qry_result = $focus->db->query($curr_pl_qry); |
653
|
|
|
|
654
|
|
|
//build the array with current user list information |
655
|
|
|
$curr_pl_arr = array(); |
656
|
|
|
while ($row = $focus->db->fetchByAssoc($curr_pl_qry_result)){$curr_pl_arr[] = $row;} |
657
|
|
|
//check to see if user is already there in prospect list |
658
|
|
|
$already_here = 'false'; |
659
|
|
|
$exempt_id = ''; |
660
|
|
|
|
661
|
|
|
foreach($curr_pl_arr as $user_list){ |
662
|
|
|
foreach($pl_arr as $v){ |
663
|
|
|
//if list is exempt list |
664
|
|
|
if($v['list_type'] == 'exempt'){ |
665
|
|
|
//save the exempt list id for later use |
666
|
|
|
$exempt_id = $v['id']; |
667
|
|
|
//check to see if user is already in this exempt list |
668
|
|
|
if(in_array($v['id'], $user_list)){ |
669
|
|
|
$already_here = 'true'; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
break 2; |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
//unsubscribe subscripted newsletter |
678
|
|
|
foreach($pl_arr as $subscription_list){ |
679
|
|
|
//create a new instance of the prospect list |
680
|
|
|
$exempt_list = new ProspectList(); |
681
|
|
|
$exempt_list->retrieve($subscription_list['id']); |
682
|
|
|
$exempt_list->load_relationship($relationship); |
683
|
|
|
//if list type is default, then delete the relationship |
684
|
|
|
//if list type is exempt, then add the relationship to unsubscription list |
685
|
|
|
if($subscription_list['list_type'] == 'exempt') { |
686
|
|
|
$exempt_list->$relationship->add($focus->id); |
687
|
|
|
}elseif($subscription_list['list_type'] == 'default' || $subscription_list['list_type'] == 'test'){ |
|
|
|
|
688
|
|
|
//if list type is default or test, then delete the relationship |
689
|
|
|
//$exempt_list->$relationship->delete($subscription_list['id'],$focus->id); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
if($already_here =='true'){ |
|
|
|
|
695
|
|
|
//do nothing, user is already exempted |
696
|
|
|
|
697
|
|
|
}else{ |
698
|
|
|
//user is not exempted yet , so add to unsubscription list |
699
|
|
|
|
700
|
|
|
|
701
|
|
|
$exempt_result = $exempt_list->retrieve($exempt_id); |
702
|
|
|
if($exempt_result == null) |
703
|
|
|
{//error happened while retrieving this list |
704
|
|
|
return; |
705
|
|
|
} |
706
|
|
|
$GLOBALS['log']->debug("In Campaigns Util, loading relationship: ".$relationship); |
707
|
|
|
$exempt_list->load_relationship($relationship); |
708
|
|
|
$exempt_list->$relationship->add($focus->id); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
|
714
|
|
|
/* |
715
|
|
|
*This function will return a string to the newsletter wizard if campaign check |
716
|
|
|
*does not return 100% healthy. |
717
|
|
|
*/ |
718
|
|
|
function diagnose(&$errors = array(), &$links = array()) |
719
|
|
|
{ |
720
|
|
|
global $mod_strings; |
721
|
|
|
global $current_user; |
722
|
|
|
|
723
|
|
|
$errors = array( |
724
|
|
|
'mailbox1' => false, |
725
|
|
|
'mailbox2' => false, |
726
|
|
|
'admin' => false, |
727
|
|
|
'scheduler1' => false, |
728
|
|
|
'scheduler2' => false, |
729
|
|
|
); |
730
|
|
|
|
731
|
|
|
$links = array( |
732
|
|
|
'scheduler' => false, |
733
|
|
|
'email' => false, |
734
|
|
|
); |
735
|
|
|
|
736
|
|
|
$msg = " <table class='detail view small' width='100%'><tr><td> ".$mod_strings['LNK_CAMPAIGN_DIGNOSTIC_LINK']."</td></tr>"; |
737
|
|
|
|
738
|
|
|
//Start with email components |
739
|
|
|
//monitored mailbox section |
740
|
|
|
$focus = new Administration(); |
741
|
|
|
$focus->retrieveSettings(); //retrieve all admin settings. |
742
|
|
|
|
743
|
|
|
|
744
|
|
|
//run query for mail boxes of type 'bounce' |
745
|
|
|
$email_health = 0; |
746
|
|
|
$email_components = 2; |
747
|
|
|
$mbox_qry = "select * from inbound_email where deleted ='0' and mailbox_type = 'bounce'"; |
748
|
|
|
$mbox_res = $focus->db->query($mbox_qry); |
749
|
|
|
|
750
|
|
|
$mbox = array(); |
751
|
|
|
while ($mbox_row = $focus->db->fetchByAssoc($mbox_res)){$mbox[] = $mbox_row;} |
752
|
|
|
//if the array is not empty, then set "good" message |
753
|
|
|
if(isset($mbox) && count($mbox)>0){ |
|
|
|
|
754
|
|
|
//everything is ok, do nothing |
755
|
|
|
|
756
|
|
|
}else{ |
757
|
|
|
//if array is empty, then increment health counter |
758
|
|
|
$email_health =$email_health +1; |
759
|
|
|
$msg .= "<tr><td ><font color='red'><b>". $mod_strings['LBL_MAILBOX_CHECK1_BAD']."</b></font></td></tr>"; |
760
|
|
|
$errors['mailbox1'] = $mod_strings['LBL_MAILBOX_CHECK1_BAD']; |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
|
764
|
|
|
if (strstr($focus->settings['notify_fromaddress'], 'example.com')){ |
765
|
|
|
//if "from_address" is the default, then set "bad" message and increment health counter |
766
|
|
|
$email_health =$email_health +1; |
767
|
|
|
$msg .= "<tr><td ><font color='red'><b> ".$mod_strings['LBL_MAILBOX_CHECK2_BAD']." </b></font></td></tr>"; |
768
|
|
|
$errors['mailbox2'] = $mod_strings['LBL_MAILBOX_CHECK2_BAD']; |
769
|
|
|
}else{ |
|
|
|
|
770
|
|
|
//do nothing, address has been changed |
771
|
|
|
} |
772
|
|
|
//if health counter is above 1, then show admin link |
773
|
|
|
if($email_health>0){ |
774
|
|
|
if (is_admin($current_user)){ |
775
|
|
|
$lnk = 'index.php?module=Campaigns&action=WizardEmailSetup'; |
776
|
|
|
$msg.="<tr><td ><a href='"; |
777
|
|
|
if(isset($_REQUEST['return_module'])){ |
778
|
|
|
$lnk .="&return_module=".$_REQUEST['return_module']; |
779
|
|
|
} |
780
|
|
|
if(isset($_REQUEST['return_action'])){ |
781
|
|
|
$lnk .="&return_action=".$_REQUEST['return_action']; |
782
|
|
|
} |
783
|
|
|
$msg .= $lnk; |
784
|
|
|
$links['email'] = $lnk; |
785
|
|
|
$msg.="'>".$mod_strings['LBL_EMAIL_SETUP_WIZ']."</a></td></tr>"; |
786
|
|
|
}else{ |
787
|
|
|
$msg.="<tr><td >".$mod_strings['LBL_NON_ADMIN_ERROR_MSG']."</td></tr>"; |
788
|
|
|
$errors['admin'] = $mod_strings['LBL_NON_ADMIN_ERROR_MSG']; |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
|
794
|
|
|
// proceed with scheduler components |
795
|
|
|
|
796
|
|
|
//create and run the scheduler queries |
797
|
|
|
$sched_qry = "select job, name, status from schedulers where deleted = 0 and status = 'Active'"; |
798
|
|
|
$sched_res = $focus->db->query($sched_qry); |
799
|
|
|
$sched_health = 0; |
800
|
|
|
$sched = array(); |
801
|
|
|
$check_sched1 = 'function::runMassEmailCampaign'; |
802
|
|
|
$check_sched2 = 'function::pollMonitoredInboxesForBouncedCampaignEmails'; |
803
|
|
|
$sched_mes = ''; |
804
|
|
|
$sched_mes_body = ''; |
805
|
|
|
$scheds = array(); |
806
|
|
|
|
807
|
|
|
while ($sched_row = $focus->db->fetchByAssoc($sched_res)){$scheds[] = $sched_row;} |
808
|
|
|
//iterate through and see which jobs were found |
809
|
|
|
foreach ($scheds as $funct){ |
810
|
|
|
if( ($funct['job']==$check_sched1) || ($funct['job']==$check_sched2)){ |
811
|
|
|
if($funct['job']==$check_sched1){ |
812
|
|
|
$check_sched1 ="found"; |
813
|
|
|
}else{ |
814
|
|
|
$check_sched2 ="found"; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
} |
818
|
|
|
} |
819
|
|
|
//determine if error messages need to be displayed for schedulers |
820
|
|
|
if($check_sched2 != 'found'){ |
821
|
|
|
$sched_health =$sched_health +1; |
822
|
|
|
$msg.= "<tr><td><font color='red'><b>".$mod_strings['LBL_SCHEDULER_CHECK1_BAD']."</b></font></td></tr>"; |
823
|
|
|
$errors['scheduler1'] = $mod_strings['LBL_SCHEDULER_CHECK1_BAD']; |
824
|
|
|
} |
825
|
|
|
if($check_sched1 != 'found'){ |
826
|
|
|
$sched_health =$sched_health +1; |
827
|
|
|
$msg.= "<tr><td><font color='red'><b>".$mod_strings['LBL_SCHEDULER_CHECK2_BAD']."</b></font></td></tr>"; |
828
|
|
|
$errors['scheduler2'] = $mod_strings['LBL_SCHEDULER_CHECK2_BAD']; |
829
|
|
|
} |
830
|
|
|
//if health counter is above 1, then show admin link |
831
|
|
|
if($sched_health>0){ |
832
|
|
|
global $current_user; |
833
|
|
|
if (is_admin($current_user)){ |
834
|
|
|
$link = 'index.php?module=Schedulers&action=index'; |
835
|
|
|
$msg.="<tr><td ><a href='$link'>".$mod_strings['LBL_SCHEDULER_LINK']."</a></td></tr>"; |
836
|
|
|
$links['scheduler'] = $link; |
837
|
|
|
}else{ |
838
|
|
|
$msg.="<tr><td >".$mod_strings['LBL_NON_ADMIN_ERROR_MSG']."</td></tr>"; |
839
|
|
|
$errors['admin'] = $mod_strings['LBL_NON_ADMIN_ERROR_MSG']; |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
//determine whether message should be returned |
845
|
|
|
if(($sched_health + $email_health)>0){ |
846
|
|
|
$msg .= "</table> "; |
847
|
|
|
}else{ |
848
|
|
|
$msg = ''; |
849
|
|
|
} |
850
|
|
|
return $msg; |
851
|
|
|
} |
852
|
|
|
|
853
|
|
|
|
854
|
|
|
/** |
855
|
|
|
* Handle campaign log entry creation for mail-merge activity. The function will be called by the soap component. |
856
|
|
|
* |
857
|
|
|
* @param String campaign_id Primary key of the campaign |
858
|
|
|
* @param array targets List of keys for entries from prospect_lists_prosects table |
859
|
|
|
*/ |
860
|
|
|
function campaign_log_mail_merge($campaign_id, $targets) { |
861
|
|
|
|
862
|
|
|
$campaign= new Campaign(); |
863
|
|
|
$campaign->retrieve($campaign_id); |
864
|
|
|
|
865
|
|
|
if (empty($campaign->id)) { |
866
|
|
|
$GLOBALS['log']->debug('set_campaign_merge: Invalid campaign id'. $campaign_id); |
867
|
|
|
} else { |
868
|
|
|
foreach ($targets as $target_list_id) { |
869
|
|
|
$pl_query = "select * from prospect_lists_prospects where id='".$GLOBALS['db']->quote($target_list_id)."'"; |
870
|
|
|
$result=$GLOBALS['db']->query($pl_query); |
871
|
|
|
$row=$GLOBALS['db']->fetchByAssoc($result); |
872
|
|
|
if (!empty($row)) { |
873
|
|
|
write_mail_merge_log_entry($campaign_id,$row); |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
} |
879
|
|
|
/** |
880
|
|
|
* Function creates a campaign_log entry for campaigns processesed using the mail-merge feature. If any entry |
881
|
|
|
* exist the hit counter is updated. target_tracker_key is used to locate duplicate entries. |
882
|
|
|
* @param string campaign_id Primary key of the campaign |
883
|
|
|
* @param array $pl_row A row of data from prospect_lists_prospects table. |
884
|
|
|
*/ |
885
|
|
|
function write_mail_merge_log_entry($campaign_id,$pl_row) { |
886
|
|
|
|
887
|
|
|
//Update the log entry if it exists. |
888
|
|
|
$update="update campaign_log set hits=hits+1 where campaign_id='".$GLOBALS['db']->quote($campaign_id)."' and target_tracker_key='" . $GLOBALS['db']->quote($pl_row['id']) . "'"; |
889
|
|
|
$result=$GLOBALS['db']->query($update); |
890
|
|
|
|
891
|
|
|
//get affected row count... |
892
|
|
|
$count=$GLOBALS['db']->getAffectedRowCount(); |
893
|
|
|
if ($count==0) { |
894
|
|
|
$data=array(); |
895
|
|
|
|
896
|
|
|
$data['id']="'" . create_guid() . "'"; |
897
|
|
|
$data['campaign_id']="'" . $GLOBALS['db']->quote($campaign_id) . "'"; |
898
|
|
|
$data['target_tracker_key']="'" . $GLOBALS['db']->quote($pl_row['id']) . "'"; |
899
|
|
|
$data['target_id']="'" . $GLOBALS['db']->quote($pl_row['related_id']) . "'"; |
900
|
|
|
$data['target_type']="'" . $GLOBALS['db']->quote($pl_row['related_type']) . "'"; |
901
|
|
|
$data['activity_type']="'targeted'"; |
902
|
|
|
$data['activity_date']="'" . TimeDate::getInstance()->nowDb() . "'"; |
903
|
|
|
$data['list_id']="'" . $GLOBALS['db']->quote($pl_row['prospect_list_id']) . "'"; |
904
|
|
|
$data['hits']=1; |
905
|
|
|
$data['deleted']=0; |
906
|
|
|
$insert_query="INSERT into campaign_log (" . implode(",",array_keys($data)) . ")"; |
907
|
|
|
$insert_query.=" VALUES (" . implode(",",array_values($data)) . ")"; |
908
|
|
|
$GLOBALS['db']->query($insert_query); |
909
|
|
|
} |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
function track_campaign_prospects($focus){ |
913
|
|
|
$campaign_id = $GLOBALS['db']->quote($focus->id); |
914
|
|
|
$delete_query="delete from campaign_log where campaign_id='".$campaign_id."' and activity_type='targeted'"; |
915
|
|
|
$focus->db->query($delete_query); |
916
|
|
|
|
917
|
|
|
$current_date = $focus->db->now(); |
918
|
|
|
$guidSQL = $focus->db->getGuidSQL(); |
919
|
|
|
|
920
|
|
|
$insert_query= "INSERT INTO campaign_log (id,activity_date, campaign_id, target_tracker_key,list_id, target_id, target_type, activity_type, deleted"; |
921
|
|
|
$insert_query.=')'; |
922
|
|
|
$insert_query.="SELECT {$guidSQL}, $current_date, plc.campaign_id,{$guidSQL},plp.prospect_list_id, plp.related_id, plp.related_type,'targeted',0 "; |
923
|
|
|
$insert_query.="FROM prospect_lists INNER JOIN prospect_lists_prospects plp ON plp.prospect_list_id = prospect_lists.id"; |
924
|
|
|
$insert_query.=" INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = prospect_lists.id"; |
925
|
|
|
$insert_query.=" WHERE plc.campaign_id='".$GLOBALS['db']->quote($focus->id)."'"; |
926
|
|
|
$insert_query.=" AND prospect_lists.deleted=0"; |
927
|
|
|
$insert_query.=" AND plc.deleted=0"; |
928
|
|
|
$insert_query.=" AND plp.deleted=0"; |
929
|
|
|
$insert_query.=" AND prospect_lists.list_type!='test' AND prospect_lists.list_type not like 'exempt%'"; |
930
|
|
|
$focus->db->query($insert_query); |
931
|
|
|
|
932
|
|
|
global $mod_strings; |
933
|
|
|
//return success message |
934
|
|
|
return $mod_strings['LBL_DEFAULT_LIST_ENTRIES_WERE_PROCESSED']; |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
function create_campaign_log_entry($campaign_id, $focus, $rel_name, $rel_bean, $target_id = ''){ |
938
|
|
|
global $timedate; |
939
|
|
|
|
940
|
|
|
$target_ids = array(); |
941
|
|
|
//check if this is specified for one target/contact/prospect/lead (from contact/lead detail subpanel) |
942
|
|
|
if(!empty($target_id)){ |
943
|
|
|
$target_ids[] = $target_id; |
944
|
|
|
}else{ |
945
|
|
|
//this is specified for all, so load target/prospect relationships (mark as sent button) |
946
|
|
|
$focus->load_relationship($rel_name); |
947
|
|
|
$target_ids = $focus->$rel_name->get(); |
948
|
|
|
|
949
|
|
|
} |
950
|
|
|
if(count($target_ids)>0){ |
951
|
|
|
|
952
|
|
|
|
953
|
|
|
//retrieve the target beans and create campaign log entry |
954
|
|
|
foreach($target_ids as $id){ |
955
|
|
|
//perform duplicate check |
956
|
|
|
$dup_query = "select id from campaign_log where campaign_id = '$campaign_id' and target_id = '$id'"; |
957
|
|
|
$dup_result = $focus->db->query($dup_query); |
958
|
|
|
$row = $focus->db->fetchByAssoc($dup_result); |
959
|
|
|
|
960
|
|
|
//process if this is not a duplicate campaign log entry |
961
|
|
|
if(empty($row)){ |
962
|
|
|
//create campaign tracker id and retrieve related bio bean |
963
|
|
|
$tracker_id = create_guid(); |
964
|
|
|
$rel_bean->retrieve($id); |
965
|
|
|
|
966
|
|
|
//create new campaign log record. |
967
|
|
|
$campaign_log = new CampaignLog(); |
968
|
|
|
$campaign_log->campaign_id = $campaign_id; |
969
|
|
|
$campaign_log->target_tracker_key = $tracker_id; |
970
|
|
|
$campaign_log->target_id = $rel_bean->id; |
971
|
|
|
$campaign_log->target_type = $rel_bean->module_dir; |
972
|
|
|
$campaign_log->activity_type = 'targeted'; |
973
|
|
|
$campaign_log->activity_date=$timedate->now(); |
974
|
|
|
//save the campaign log entry |
975
|
|
|
$campaign_log->save(); |
976
|
|
|
} |
977
|
|
|
} |
978
|
|
|
} |
979
|
|
|
|
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
/* |
983
|
|
|
* This function will return an array that has been formatted to work as a Quick Search Object for prospect lists |
984
|
|
|
*/ |
985
|
|
|
function getProspectListQSObjects($source = '', $return_field_name='name', $return_field_id='id' ) { |
986
|
|
|
global $app_strings; |
987
|
|
|
//if source has not been specified, then search across all prospect lists |
988
|
|
|
if(empty($source)){ |
989
|
|
|
$qsProspectList = array('method' => 'query', |
990
|
|
|
'modules'=> array('ProspectLists'), |
991
|
|
|
'group' => 'and', |
992
|
|
|
'field_list' => array('name', 'id'), |
993
|
|
|
'populate_list' => array('prospect_list_name', 'prospect_list_id'), |
994
|
|
|
'conditions' => array( array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'') ), |
995
|
|
|
'order' => 'name', |
996
|
|
|
'limit' => '30', |
997
|
|
|
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']); |
998
|
|
|
}else{ |
999
|
|
|
//source has been specified use it to tell quicksearch.js which html input to use to get filter value |
1000
|
|
|
$qsProspectList = array('method' => 'query', |
1001
|
|
|
'modules'=> array('ProspectLists'), |
1002
|
|
|
'group' => 'and', |
1003
|
|
|
'field_list' => array('name', 'id'), |
1004
|
|
|
'populate_list' => array($return_field_name, $return_field_id), |
1005
|
|
|
'conditions' => array( |
1006
|
|
|
array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>''), |
1007
|
|
|
//this condition has the source parameter defined, meaning the query will take the value specified below |
1008
|
|
|
array('name'=>'list_type', 'op'=>'like_custom', 'end'=>'%','value'=>'', 'source' => $source) |
1009
|
|
|
), |
1010
|
|
|
'order' => 'name', |
1011
|
|
|
'limit' => '30', |
1012
|
|
|
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']); |
1013
|
|
|
|
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
return $qsProspectList; |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
|
1020
|
|
|
?> |
1021
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.