Cheetah
greet.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_CLASSES . 'ChWsbEmailTemplates.php');
12 
13 // --------------- page variables
14 
15 $_page['name_index'] = ch_get('fullpage') == 1 ? 7 : 44;
16 $logged['member'] = member_auth(0, false);
17 
18 // --------------- page components
19 
20 //define ajax mode
21 $bAjxMod = isset($_SERVER['HTTP_X_REQUESTED_WITH'])
22 && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
23 
24 if ($bAjxMod) {
25  header('Content-Type: text/html; charset=utf-8');
26  echo MsgBox(getMainCode());
27  exit;
28 }
29 
30 $_ni = $_page['name_index'];
31 $_page_cont[$_ni]['page_main_code'] = DesignBoxContent(_t('_Send virtual kiss'), getMainCode(),
32  $oTemplConfig->PageVkiss_db_num);
33 $_page_cont[$_ni]['body_onload'] = '';
34 // --------------- [END] page components
35 
36 PageCode();
37 
38 // --------------- page components functions
39 
43 function getMainCode()
44 {
45  global $_page;
46 
47  $member['ID'] = getLoggedId();
48  $member['Password'] = getLoggedPassword();
49 
50  if (false != ch_get('ConfCode') && false != ch_get('sendto')) {
51  $recipientID = (int)ch_get('sendto');
52  } else {
53  //check post value
54  $recipientID = isset($_POST['sendto']) ? $_POST['sendto'] : -1;
55  }
56 
57  $recipient = getProfileInfo($recipientID);
58  $isCheckVisitorGreeting = true;
59 
60  if (!$recipient || $recipientID == $member['ID']) {
61  return MsgBox(_t('_Error Occured'));
62  }
63 
64  ob_start();
65  ?>
66  <table width="100%" cellpadding="4" cellspacing="4" border="0">
67  <tr>
68  <td align="center" class="text2">__content__<br /></td>
69  </tr>
70  </table>
71  <?php
72  $sResTmpl = ob_get_clean();
73 
74  $ret = '';
75  $sKissKey = '_Send virtual kiss';
76  $sJQueryJS = genAjaxyPopupJS($recipientID);
77 
78  $_page['header'] = _t($sKissKey);
79 
80  if ($_GET['ConfCode'] && $_GET['from'] &&
81  (strcmp($_GET['ConfCode'], base64_encode(base64_encode(crypt($_GET['from'], CRYPT_EXT_DES ? "vkiss_sec" : "vk")))) === 0)
82  ) {
83  $member['ID'] = (int)$_GET['from'];
84  $isCheckVisitorGreeting = false;
85  }
86 
87  //
88  // Check if member can send messages
89  $check_res = checkAction($member['ID'], ACTION_ID_SEND_VKISS);
91  $_page['header_text'] = _t($sKissKey . '3');
92  $ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl,
93  array('content' => $check_res[CHECK_ACTION_MESSAGE]));
94 
95  return $ret . $sJQueryJS;
96  }
97 
98  $action_result = "";
99  // Perform sending
100  $send_result = MemberSendVKiss($member, $recipient, $isCheckVisitorGreeting);
101  switch ($send_result) {
102  case 1:
103  $action_result .= _t_err("_VKISS_BAD");
104  break;
105  case 7:
106  $action_result .= _t_err("_VKISS_BAD_COUSE_B");
107  break;
108  case 10:
109  $action_result .= _t_err("_VKISS_BAD_COUSE_C");
110  break;
111  case 13:
112  $action_result .= _t_err("_VKISS_BAD_COUSE_A3");
113  break;
114  case 23:
115  $action_result .= _t_err("_VKISS_BAD_COUSE_X");
116  break;
117  case 24:
118  $action_result .= _t_err("_VKISS_BAD_COUSE_Y");
119  break;
120  default:
121  $action_result .= _t("_VKISS_OK");
122  break;
123  }
124  if ($send_result == 0) {
125  $_page['header_text'] = _t($sKissKey . '2');
126  } else {
127  $_page['header_text'] = _t($sKissKey . '3');
128  }
129 
130  $ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $action_result));
131 
132  return $ret . $sJQueryJS;
133 }
134 
138 function MemberSendVKiss($member, $recipient, $isCheckVisitorGreeting = true)
139 {
140  global $logged;
141 
142  // Check if recipient is active
143  if ('Active' != $recipient['Status']) {
144  return 7;
145  }
146 
147  // block members
148  if ($recipient['ID'] && $member['ID'] && isBlocked((int)$recipient['ID'], (int)$member['ID'])) {
149  return 24;
150  }
151 
152  // Get sender info
153  $sender = getProfileInfo($member['ID']);
154 
155  // Send email notification
156  $rEmailTemplate = new ChWsbEmailTemplates();
157  if ($logged['member'] || !$isCheckVisitorGreeting) {
158  $aTemplate = $rEmailTemplate->getTemplate('t_VKiss', $_COOKIE['memberID']);
159  } else {
160  $aTemplate = $rEmailTemplate->getTemplate('t_VKiss_visitor');
161  }
162 
163  $sConfCode = urlencode(base64_encode(base64_encode(crypt($recipient['ID'], CRYPT_EXT_DES ? "vkiss_sec" : "vk"))));
164 
165  // parse the email template ;
166  $sProfileLink = $sender
167  ? '<a href="' . getProfileLink($member['ID']) . '">' . getNickName($sender['ID']) . '</a>'
168  : '<b>' . _t("_Visitor") . '</b>';
169 
170  $sKissLink = $sender
171  ? '<a href="' . CH_WSB_URL_ROOT . 'greet.php?fullpage=1&sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $sConfCode . '">' . CH_WSB_URL_ROOT . 'greet.php?sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $sConfCode . '</a>'
172  : '<a href="' . CH_WSB_URL_ROOT . 'communicator.php">' . CH_WSB_URL_ROOT . 'communicator.php</a>';
173 
174  $aRepl = array(
175  '<ConfCode>' => $sConfCode,
176  '<ProfileReference>' => $sProfileLink,
177  '<VKissLink>' => $sKissLink,
178  '<RealName>' => getNickName($recipient['ID']),
179  '<SiteName>' => CH_WSB_URL_ROOT,
180  );
181 
182  $aTemplate['Body'] = str_replace(array_keys($aRepl), array_values($aRepl), $aTemplate['Body']);
183  $mail_ret = sendMail($recipient['Email'], $aTemplate['Subject'], $aTemplate['Body'], $recipient['ID']);
184 
185  // Send message into the member's site personal mailbox;
186 
187  $aTemplate['Subject'] = process_db_input($aTemplate['Subject'], CH_TAGS_NO_ACTION);
188  $aTemplate['Body'] = process_db_input($aTemplate['Body'], CH_TAGS_NO_ACTION);
189 
190  $sender['ID'] = (!$sender['ID']) ? 0 : $sender['ID'];
191 
192  $sQuery =
193  "
194  INSERT INTO
195  `sys_messages`
196  SET
197  `Date` = NOW(),
198  `Sender` = '{$sender['ID']}',
199  `Recipient` = '{$recipient['ID']}',
200  `Subject` = '{$aTemplate['Subject']}',
201  `Text` = '{$aTemplate['Body']}',
202  `New` = '1',
203  `Type` = 'greeting'
204  ";
205  db_res($sQuery);
206 
207  if (!$mail_ret) {
208  return 10;
209  }
210 
211  // Insert kiss into database
212  $kiss_arr = db_arr("SELECT `ID` FROM `sys_greetings` WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']} LIMIT 1",
213  0);
214  if (!$kiss_arr) {
215  $result = db_res("INSERT INTO `sys_greetings` ( `ID`, `Profile`, `Number`, `When`, `New` ) VALUES ( {$member['ID']}, {$recipient['ID']}, 1, NOW(), '1' )",
216  0);
217  } else {
218  $result = db_res("UPDATE `sys_greetings` SET `Number` = `Number` + 1, `New` = '1' WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']}",
219  0);
220  }
221 
222  if(!$result)
223  return 1;
224 
225  // If success then perform actions
226  checkAction( $member['ID'], ACTION_ID_SEND_VKISS, true );
227 
228  $oAlert = new ChWsbAlerts('greeting', 'add', 0, $member['ID'], array('Recipient' => $recipient['ID']));
229  $oAlert->alert();
230 
231  return 0;
232 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
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
getMainCode
getMainCode()
Definition: greet.php:43
$_page_cont
$_page_cont[$_ni]['page_main_code']
Definition: greet.php:31
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ACTION_ID_SEND_VKISS
const ACTION_ID_SEND_VKISS
Definition: membership_levels.inc.php:35
getLoggedPassword
getLoggedPassword()
Definition: profiles.inc.php:36
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$member
$member['ID']
Definition: member.php:33
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
$ret
$ret
Definition: index.php:39
ChWsbEmailTemplates
Definition: ChWsbEmailTemplates.php:11
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
$oAlert
$oAlert
Definition: embed.php:15
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
sendMail
sendMail( $sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID=0, $aPlus=array(), $sEmailFlag='html', $isDisableAlert=false, $bForceSend=false)
Definition: utils.inc.php:461
CHECK_ACTION_MESSAGE
const CHECK_ACTION_MESSAGE
Definition: membership_levels.inc.php:55
php
ChWsbAlerts
Definition: ChWsbAlerts.php:39
db_arr
db_arr($query, $bindings=[])
Definition: db.inc.php:76
exit
exit
Definition: cart.php:21
$_GET
$_GET['debug']
Definition: index.php:67
$_ni
if($bAjxMod) $_ni
Definition: greet.php:30
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
table
and distribute a copy of this License along with the Library You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Library or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these other than as an argument passed when the facility is then you must make a good faith effort to ensure in the event an application does not supply such function or table
Definition: license.txt:180
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
$sJQueryJS
$sJQueryJS
Definition: list_pop.php:32
CH_TAGS_NO_ACTION
const CH_TAGS_NO_ACTION
Definition: utils.inc.php:21
_t_err
_t_err( $str, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:504
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
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
$bAjxMod
$bAjxMod
Definition: greet.php:21
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
isBlocked
isBlocked($iFirstProfile, $iSecondProfile)
Definition: utils.inc.php:128
$logged
$logged['member']
Definition: greet.php:16
$_page
$_page['name_index']
Definition: greet.php:15
genAjaxyPopupJS
genAjaxyPopupJS($iTargetID, $sDivID='ajaxy_popup_result_div', $sRedirect='')
Definition: design.inc.php:242
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
MemberSendVKiss
MemberSendVKiss($member, $recipient, $isCheckVisitorGreeting=true)
Definition: greet.php:138
DesignBoxContent
DesignBoxContent($title, $content, $db_num=0, $caption_item='', $bottom_item='')
Definition: design.inc.php:78
$oTemplConfig
$oTemplConfig
Definition: params.inc.php:90
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10