Cheetah
tellfriend.php
Go to the documentation of this file.
1 <?php
2 
8 require_once('inc/header.inc.php');
9 require_once(CH_DIRECTORY_PATH_INC . 'design.inc.php');
10 require_once(CH_DIRECTORY_PATH_INC . 'profiles.inc.php');
11 require_once(CH_DIRECTORY_PATH_INC . 'utils.inc.php');
12 require_once(CH_DIRECTORY_PATH_CLASSES . 'ChWsbEmailTemplates.php');
13 
14 ch_import('ChTemplFormView');
15 
16 // --------------- page variables and login
17 
18 $_page['name_index'] = 29;
19 $_page['css_name'] = array('forms_adv.css');
20 
21 $_page['header'] = _t("_Tell a friend");
22 $_page['header_text'] = _t("_Tell a friend");
23 
25 if (isset($_GET['ID'])) {
26  $profileID = (int)$_GET['ID'];
27 } else {
28  if (isset($_POST['ID'])) {
29  $profileID = (int)$_POST['ID'];
30  }
31 }
32 
33 $iSenderID = getLoggedId();
35 
36 // --------------- page components
37 $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
38 
39 $sCaption = ($profileID) ? _t('_TELLAFRIEND2', $site['title']) : _t('_TELLAFRIEND', $site['title']);
40 
41 $aForm = array(
42  'form_attrs' => array(
43  'id' => 'invite_friend',
44  'name' => 'invite_friend',
45  'action' => CH_WSB_URL_ROOT . 'tellfriend.php',
46  'method' => 'post',
47  'onsubmit' => "return ch_ajax_form_check(this)",
48  ),
49  'params' => array(
50  'db' => array(
51  'submit_name' => 'do_submit',
52  // we need alternative hidden field name here, instead of submit, becuase AJAX submit doesn't pass submit button value
53  ),
54  ),
55  'inputs' => array(
56  'header1' => array(
57  'type' => 'block_header',
58  'caption' => $sCaption,
59  ),
60  'do_submit' => array(
61  'type' => 'hidden',
62  'name' => 'do_submit', // hidden submit field for AJAX submit
63  'value' => 1,
64  ),
65  'id' => array(
66  'type' => 'hidden',
67  'name' => 'ID',
68  'value' => $profileID,
69  ),
70  'sender_name' => array(
71  'type' => 'text',
72  'name' => 'sender_name',
73  'caption' => _t("_Your name"),
74  'value' => getNickName($aSenderInfo['ID']),
75  ),
76  'sender_email' => array(
77  'type' => 'text',
78  'name' => 'sender_email',
79  'caption' => _t('_Your email'),
80  'required' => true,
81  'value' => $aSenderInfo['Email'],
82  'checker' => array(
83  'func' => 'email',
84  'error' => _t('_Incorrect Email'),
85  ),
86  ),
87  'recipient_email' => array(
88  'type' => 'text',
89  'name' => 'recipient_email',
90  'caption' => _t('_Friend email'),
91  'required' => true,
92  'value' => '',
93  'checker' => array(
94  'func' => 'email',
95  'error' => _t('_sys_adm_form_err_required_field'),
96  ),
97  ),
98  'captcha' => array(
99  'type' => 'captcha',
100  'caption' => _t('_Enter what you see'),
101  'name' => 'securityImageValue',
102  'required' => true,
103  'dynamic' => $bAjaxMode,
104  'checker' => array(
105  'func' => 'captcha',
106  'error' => _t( '_Incorrect Captcha' ),
107  ),
108  ),
109  'submit_send' => array(
110  'type' => 'submit',
111  'name' => 'submit_send',
112  'value' => _t("_Send Letter"),
113  ),
114  )
115 );
116 
117 if(isLogged())
118  unset($aForm['inputs']['captcha']);
119 
120 // generate form or form result content
122 $oForm->initChecker();
123 if ($oForm->isSubmittedAndValid())
124  $sPageCode = MsgBox(_t(SendTellFriend($iSenderID) ? '_Email was successfully sent' : '_Email sent failed'));
125 else
126  $sPageCode = $oForm->getCode();
127 
128 // output AJAX form submission result
129 if (ch_get('ChAjaxSubmit')) {
130  header('Content-type:text/html;charset=utf-8');
131  echo $sPageCode;
132  exit;
133 }
134 
135 $sPageCode = $GLOBALS['oSysTemplate']->parseHtmlByName('default_margin.html', array('content' => $sPageCode));
136 
137 // output ajax popup
138 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
139  $aVarsPopup = array(
140  'title' => $_page['header'],
141  'content' => $sPageCode,
142  );
143  header('Content-type:text/html;charset=utf-8');
144  echo $GLOBALS['oFunctions']->transBox($GLOBALS['oSysTemplate']->parseHtmlByName('popup.html', $aVarsPopup), true);
145  exit;
146 }
147 
148 // output regular page
149 $_ni = $_page['name_index'];
150 $_page_cont[$_ni]['page_code'] = $sPageCode;
151 PageCode();
152 
153 // --------------- page components functions
154 
159 function SendTellFriend($iSenderID = 0)
160 {
162 
163  $sSenderEmail = clear_xss(ch_get('sender_email'));
164  if(strlen(trim($sSenderEmail)) <= 0)
165  return 0;
166 
167  $sSenderName = strmaxtextlen(ch_get('sender_name'), 16);
168  $sSenderLink = $iSenderID != 0 ? getProfileLink($iSenderID) : CH_WSB_URL_ROOT;
169 
170  $sRecipientEmail = clear_xss(ch_get('recipient_email'));
171  if(strlen(trim($sRecipientEmail)) <= 0)
172  return 0;
173 
174  $sLinkAdd = $iSenderID > 0 ? 'idFriend=' . $iSenderID : '';
175  $rEmailTemplate = new ChWsbEmailTemplates();
176  if ($profileID) {
177  $aTemplate = $rEmailTemplate->getTemplate('t_TellFriendProfile', getLoggedId());
178  $Link = getProfileLink($profileID, $sLinkAdd);
179  }
180  else {
181  $aTemplate = $rEmailTemplate->getTemplate('t_TellFriend', getLoggedId());
182  $Link = CH_WSB_URL_ROOT;
183  if (strlen($sLinkAdd) > 0)
184  $Link .= '?' . $sLinkAdd;
185  }
186 
187  return sendMail($sRecipientEmail, $aTemplate['Subject'], $aTemplate['Body'], '', array(
188  'Link' => $Link,
189  'SenderName' => $sSenderName,
190  'SenderLink' => $sSenderLink
191  ));
192 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
$_page_cont
$_page_cont[$_ni]['page_code']
Definition: tellfriend.php:150
$aSenderInfo
$aSenderInfo
Definition: tellfriend.php:34
ChTemplFormView
Definition: ChTemplFormView.php:11
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChWsbEmailTemplates
Definition: ChWsbEmailTemplates.php:11
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
sendMail
sendMail( $sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID=0, $aPlus=array(), $sEmailFlag='html', $isDisableAlert=false, $bForceSend=false)
Definition: utils.inc.php:461
$oForm
$oForm
Definition: tellfriend.php:121
php
isLogged
isLogged()
Definition: profiles.inc.php:24
$profileID
$profileID
Definition: tellfriend.php:24
exit
exit
Definition: cart.php:21
$_ni
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_ni
Definition: tellfriend.php:149
$_GET
$_GET['debug']
Definition: index.php:67
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
strmaxtextlen
strmaxtextlen($sInput, $iMaxLen=60)
Definition: utils.inc.php:207
$site
$site['ver']
Definition: version.inc.php:8
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
PageCode
PageCode($oTemplate=null)
Definition: design.inc.php:91
$_page
$_page['name_index']
Definition: tellfriend.php:18
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
$bAjaxMode
$bAjaxMode
Definition: tellfriend.php:37
$aForm
$aForm
Definition: tellfriend.php:41
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
$sPageCode
else $sPageCode
Definition: tellfriend.php:126
$sCaption
$sCaption
Definition: tellfriend.php:39
SendTellFriend
SendTellFriend($iSenderID=0)
Definition: tellfriend.php:159
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
clear_xss
clear_xss($val)
Definition: utils.inc.php:700