forked from vtiger-crm/vtigercrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendSupportNotification.php
132 lines (101 loc) · 4.73 KB
/
SendSupportNotification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
////////////////////////////////////////////////////
// PHPMailer - PHP email class
//
// Class for sending email using either
// sendmail, PHP mail(), or SMTP. Methods are
// based upon the standard AspEmail(tm) classes.
//
// Copyright (C) 2001 - 2003 Brent R. Matzelle
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
/**
* PHPMailer - PHP email transport class
* @package PHPMailer
* @author Brent R. Matzelle
* @copyright 2001 - 2003 Brent R. Matzelle
*/
require_once('include/utils/utils.php');
require("modules/Emails/mail.php");
require_once('include/logging.php');
require("config.php");
global $adb;
global $log;
global $HELPDESK_SUPPORT_EMAIL_ID,$HELPDESK_SUPPORT_NAME;
$log =& LoggerManager::getLogger('SendSupportNotification');
$log->debug(" invoked SendSupportNotification ");
// retrieve the translated strings.
$app_strings = return_application_language($current_language);
//To send email notification before a week
$query="select vtiger_contactdetails.contactid,vtiger_contactdetails.email,vtiger_contactdetails.firstname,vtiger_contactdetails.lastname,contactid from vtiger_customerdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_customerdetails.customerid inner join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_customerdetails.customerid where vtiger_crmentity.deleted=0 and support_end_date=DATE_ADD(now(), INTERVAL 1 WEEK)";
$result = $adb->pquery($query, array());
if($adb->num_rows($result) >= 1)
{
while($result_set = $adb->fetch_array($result))
{
$content=getcontent_week($result_set["contactid"]);
$body=$content["body"];
$body = str_replace('$logo$','<img src="cid:logo" />',$body);
$subject=$content["subject"];
$status=send_mail("Support",$result_set["email"],$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$body,'',$HELPDESK_SUPPORT_EMAIL_ID
);
}
}
//comment / uncomment this line if you want to hide / show the sent mail status
//showstatus($status);
$log->debug(" Send Support Notification Befoe a week - Status: ".$status);
//To send email notification before a month
$query="select vtiger_contactdetails.contactid,vtiger_contactdetails.email,vtiger_contactdetails.firstname,vtiger_contactdetails.lastname,contactid from vtiger_customerdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_customerdetails.customerid inner join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_customerdetails.customerid where vtiger_crmentity.deleted=0 and support_end_date=DATE_ADD(now(), INTERVAL 1 MONTH)";
$result = $adb->pquery($query, array());
if($adb->num_rows($result) >= 1)
{
while($result_set = $adb->fetch_array($result))
{
$content=getcontent_month($result_set["contactid"]);
$body=$content["body"];
$body = str_replace('$logo$','<img src="cid:logo" />',$body);
$subject=$content["subject"];
$status=send_mail("Support",$result_set["email"],$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$body,'',$HELPDESK_SUPPORT_EMAIL_ID);
}
}
//comment / uncomment this line if you want to hide / show the sent mail status
//showstatus($status);
$log->debug(" Send Support Notification Befoe a Month - Status: ".$status);
//used to dispaly the sent mail status
function showstatus($status)
{
if($status == 1)
echo "Mails sent successfully";
else if($status == "")
echo "No contacts matched";
else
echo "Error while sending mails: ".$status;
}
//function used to get the header and body content of the mail to be sent.
function getcontent_month($id)
{
global $adb;
$query='select vtiger_emailtemplates.subject,vtiger_emailtemplates.body from vtiger_notificationscheduler inner join vtiger_emailtemplates on vtiger_emailtemplates.templateid=vtiger_notificationscheduler.notificationbody where schedulednotificationid=7';
$result = $adb->pquery($query, array());
$body=$adb->query_result($result,0,'body');
$body=getMergedDescription($body,$id,"Contacts");
$body=getMergedDescription($body,$id,"Users");
$res_array["subject"]=$adb->query_result($result,0,'subject');
$res_array["body"]=$body;
return $res_array;
}
//function used to get the header and body content of the mail to be sent.
function getcontent_week($id)
{
global $adb;
$query='select vtiger_emailtemplates.subject,vtiger_emailtemplates.body from vtiger_notificationscheduler inner join vtiger_emailtemplates on vtiger_emailtemplates.templateid=vtiger_notificationscheduler.notificationbody where schedulednotificationid=6';
$result = $adb->pquery($query, array());
$body=$adb->query_result($result,0,'body');
$body=getMergedDescription($body,$id,"Contacts");
$body=getMergedDescription($body,$id,"Users");
$res_array["subject"]=$adb->query_result($result,0,'subject');
$res_array["body"]=$body;
return $res_array;
}
?>