-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathtellfriend.php
192 lines (167 loc) · 5.96 KB
/
tellfriend.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
* CC-BY License - http://creativecommons.org/licenses/by/3.0/
*/
require_once('inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'profiles.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'utils.inc.php');
require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolEmailTemplates.php');
bx_import('BxTemplFormView');
// --------------- page variables and login
$_page['name_index'] = 29;
$_page['css_name'] = array('forms_adv.css');
$_page['header'] = _t("_Tell a friend");
$_page['header_text'] = _t("_Tell a friend");
$profileID = 0;
if (isset($_GET['ID'])) {
$profileID = (int)$_GET['ID'];
} else {
if (isset($_POST['ID'])) {
$profileID = (int)$_POST['ID'];
}
}
$iSenderID = getLoggedId();
$aSenderInfo = getProfileInfo($iSenderID);
// --------------- page components
$bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
$sCaption = ($profileID) ? _t('_TELLAFRIEND2', $site['title']) : _t('_TELLAFRIEND', $site['title']);
$aForm = array(
'form_attrs' => array(
'id' => 'invite_friend',
'name' => 'invite_friend',
'action' => BX_DOL_URL_ROOT . 'tellfriend.php',
'method' => 'post',
'onsubmit' => "return bx_ajax_form_check(this)",
),
'params' => array(
'db' => array(
'submit_name' => 'do_submit',
// we need alternative hidden field name here, instead of submit, becuase AJAX submit doesn't pass submit button value
),
),
'inputs' => array(
'header1' => array(
'type' => 'block_header',
'caption' => $sCaption,
),
'do_submit' => array(
'type' => 'hidden',
'name' => 'do_submit', // hidden submit field for AJAX submit
'value' => 1,
),
'id' => array(
'type' => 'hidden',
'name' => 'ID',
'value' => $profileID,
),
'sender_name' => array(
'type' => 'text',
'name' => 'sender_name',
'caption' => _t("_Your name"),
'value' => getNickName($aSenderInfo['ID']),
),
'sender_email' => array(
'type' => 'text',
'name' => 'sender_email',
'caption' => _t('_Your email'),
'required' => true,
'value' => $aSenderInfo['Email'],
'checker' => array(
'func' => 'email',
'error' => _t('_Incorrect Email'),
),
),
'recipient_email' => array(
'type' => 'text',
'name' => 'recipient_email',
'caption' => _t('_Friend email'),
'required' => true,
'value' => '',
'checker' => array(
'func' => 'email',
'error' => _t('_sys_adm_form_err_required_field'),
),
),
'captcha' => array(
'type' => 'captcha',
'caption' => _t('_Enter what you see'),
'name' => 'securityImageValue',
'required' => true,
'dynamic' => $bAjaxMode,
'checker' => array(
'func' => 'captcha',
'error' => _t( '_Incorrect Captcha' ),
),
),
'submit_send' => array(
'type' => 'submit',
'name' => 'submit_send',
'value' => _t("_Send Letter"),
),
)
);
if(isLogged())
unset($aForm['inputs']['captcha']);
// generate form or form result content
$oForm = new BxTemplFormView($aForm);
$oForm->initChecker();
if ($oForm->isSubmittedAndValid())
$sPageCode = MsgBox(_t(SendTellFriend($iSenderID) ? '_Email was successfully sent' : '_Email sent failed'));
else
$sPageCode = $oForm->getCode();
// output AJAX form submission result
if (bx_get('BxAjaxSubmit')) {
header('Content-type:text/html;charset=utf-8');
echo $sPageCode;
exit;
}
$sPageCode = $GLOBALS['oSysTemplate']->parseHtmlByName('default_margin.html', array('content' => $sPageCode));
// output ajax popup
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
$aVarsPopup = array(
'title' => $_page['header'],
'content' => $sPageCode,
);
header('Content-type:text/html;charset=utf-8');
echo $GLOBALS['oFunctions']->transBox($GLOBALS['oSysTemplate']->parseHtmlByName('popup.html', $aVarsPopup), true);
exit;
}
// output regular page
$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_code'] = $sPageCode;
PageCode();
// --------------- page components functions
/**
* send "tell a friend" email
*/
function SendTellFriend($iSenderID = 0)
{
global $profileID;
$sSenderEmail = clear_xss(bx_get('sender_email'));
if(strlen(trim($sSenderEmail)) <= 0)
return 0;
$sSenderName = strmaxtextlen(bx_get('sender_name'), 16);
$sSenderLink = $iSenderID != 0 ? getProfileLink($iSenderID) : BX_DOL_URL_ROOT;
$sRecipientEmail = clear_xss(bx_get('recipient_email'));
if(strlen(trim($sRecipientEmail)) <= 0)
return 0;
$sLinkAdd = $iSenderID > 0 ? 'idFriend=' . $iSenderID : '';
$rEmailTemplate = new BxDolEmailTemplates();
if ($profileID) {
$aTemplate = $rEmailTemplate->getTemplate('t_TellFriendProfile', getLoggedId());
$Link = getProfileLink($profileID, $sLinkAdd);
}
else {
$aTemplate = $rEmailTemplate->getTemplate('t_TellFriend', getLoggedId());
$Link = BX_DOL_URL_ROOT;
if (strlen($sLinkAdd) > 0)
$Link .= '?' . $sLinkAdd;
}
return sendMail($sRecipientEmail, $aTemplate['Subject'], $aTemplate['Body'], '', array(
'Link' => $Link,
'SenderName' => $sSenderName,
'SenderLink' => $sSenderLink
));
}