source: trunk/greet.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 7.4 KB
Line 
1<?php
2
3/***************************************************************************
4* Dolphin Smart Community Builder
5* -----------------
6* begin : Mon Mar 23 2006
7* copyright : (C) 2006 BoonEx Group
8* website : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21require_once( 'inc/header.inc.php' );
22require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
23require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
24require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolEmailTemplates.php' );
25
26// --------------- page variables
27
28$_page['name_index'] = 44;
29$_page['css_name'] = 'vkiss.css';
30
31$logged['member'] = member_auth(0, false);
32
33// --------------- page components
34
35$bAjxMod = ($_REQUEST['mode'] == 'ajax') ? true : false;
36if ($bAjxMod) {
37 echo MsgBox(getMainCode());
38 exit;
39}
40
41$_ni = $_page['name_index'];
42$_page_cont[$_ni]['page_main_code'] = DesignBoxContent(_t('_Send virtual kiss'), getMainCode(), $oTemplConfig->PageVkiss_db_num);
43$_page_cont[$_ni]['body_onload'] = '';
44// --------------- [END] page components
45
46PageCode();
47
48// --------------- page components functions
49
50/**
51 * page code function
52 */
53function getMainCode()
54{
55 global $_page;
56
57 $member['ID'] = getLoggedId();
58 $member['Password'] = getLoggedPassword;
59 $recipientID = getID( $_REQUEST['sendto'], 0 );
60 $recipient = getProfileInfo( $recipientID );
61
62 ob_start();
63 ?>
64 <table width="100%" cellpadding="4" cellspacing="4" border="0">
65 <tr>
66 <td align="center" class="text2">__content__<br/></td>
67 </tr>
68 </table>
69 <?
70 $sResTmpl = ob_get_clean();
71 $ret = '';
72 $sKissKey = '_Send virtual kiss';
73 $sJQueryJS = genAjaxyPopupJS($recipientID);
74
75 $_page['header'] = _t($sKissKey);
76
77 if ( $_REQUEST['ConfCode'] && $_REQUEST['from'] &&
78 ( strcmp( $_REQUEST['ConfCode'], base64_encode( base64_encode( crypt( $_REQUEST['from'], CRYPT_EXT_DES ? "vkiss_sec" : "vk") ) ) ) == 0 ) )
79 {
80 $member['ID'] = (int)$_REQUEST['from'];
81 }
82
83 //
84 // Check if member can send messages
85 $check_res = checkAction( $member['ID'], ACTION_ID_SEND_VKISS );
86 if ( $check_res[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
87 {
88 $_page['header_text'] = _t($sKissKey . '3');
89 $ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $check_res[CHECK_ACTION_MESSAGE]));
90 return $ret . $sJQueryJS;
91 }
92
93 $action_result = "";
94
95 // Check if recipient found
96 if( !$recipient )
97 {
98 $_page['header_text'] = _t($sKissKey . '3');
99 $sFormCode = "
100 <form method=\"GET\" action=\"{$_SERVER['PHP_SELF']}\">
101 <input class=no size=15 type=\"text\" name=\"sendto\">&nbsp;<input class=no type=\"submit\" value=\"". _t("_Send kiss") ."!\">
102 </form>";
103 $ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $sFormCode));
104 return $ret . $sJQueryJS;
105 }
106
107 // Perform sending
108 $send_result = MemberSendVKiss( $member, $recipient );
109 switch ( $send_result )
110 {
111 case 1:
112 $action_result .= _t_err( "_VKISS_BAD" );
113 break;
114 case 7:
115 $action_result .= _t_err( "_VKISS_BAD_COUSE_B" );
116 break;
117 case 10:
118 $action_result .= _t_err( "_VKISS_BAD_COUSE_C" );
119 break;
120 case 13:
121 $action_result .= _t_err( "_VKISS_BAD_COUSE_A3" );
122 break;
123 case 23:
124 $action_result .= _t_err( "_VKISS_BAD_COUSE_X" );
125 break;
126 case 24:
127 $action_result .= _t_err( "_VKISS_BAD_COUSE_Y" );
128 break;
129 default:
130 $action_result .= _t("_VKISS_OK" );
131 break;
132 }
133 if ($send_result == 0)
134 $_page['header_text'] = _t($sKissKey .'2');
135 else
136 $_page['header_text'] = _t($sKissKey .'3');
137
138 $ret = $GLOBALS['oSysTemplate']->parseHtmlByContent($sResTmpl, array('content' => $action_result));
139 return $ret . $sJQueryJS;
140}
141
142/**
143 * Send virtual kiss
144 */
145function MemberSendVKiss( $member, $recipient )
146{
147 global $logged;
148
149 // Check if recipient is active
150 if( 'Active' != $recipient['Status'] )
151 {
152 return 7;
153 }
154
155 // block members
156 if( $recipient['ID'] && $member['ID'] && isBlocked( (int)$recipient['ID'], (int)$member['ID']) ) {
157 return 24;
158 }
159
160 // Get sender info
161 $sender = getProfileInfo( $member['ID'] );
162
163 // Send email notification
164 $rEmailTemplate = new BxDolEmailTemplates();
165 if ( $logged['member'] ) {
166 $aTemplate = $rEmailTemplate -> getTemplate( 't_VKiss', $logged['member'] ) ;
167 }
168 else {
169 $aTemplate = $rEmailTemplate -> getTemplate( 't_VKiss_visitor' ) ;
170 }
171
172 $ConfCode = urlencode( base64_encode( base64_encode( crypt( $recipient['ID'], CRYPT_EXT_DES ? "vkiss_sec" : "vk" ) ) ) );
173
174 // parse the email template ;
175 $sProfileLink = $sender
176 ? '<a href="' . getProfileLink($member['ID']) . '">' . $sender['NickName'] . '</a>'
177 : '<b>' . _t("_Visitor") . '</b>';
178
179 $sKissLink = $sender
180 ? '<a href="' . BX_DOL_URL_ROOT . 'greet.php?sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $ConfCode . '">' . BX_DOL_URL_ROOT . 'greet.php?sendto=' . $member['ID'] . '&from=' . $recipient['ID'] . '&ConfCode=' . $ConfCode . '</a>'
181 : '<a href="' . BX_DOL_URL_ROOT . 'communicator.php">' . BX_DOL_URL_ROOT . 'communicator.php</a>';
182
183 $aRepl = array(
184 '<ConfCode>' => $ConfCode,
185 '<ProfileReference>' => $sProfileLink,
186 '<VKissLink>' => $sKissLink,
187 '<RealName>' => $recipient['NickName'],
188 '<SiteName>' => BX_DOL_URL_ROOT,
189 );
190
191 $aTemplate['Body'] = str_replace(array_keys($aRepl), array_values($aRepl), $aTemplate['Body']);
192 $mail_ret = sendMail( $recipient['Email'], $aTemplate['Subject'], $aTemplate['Body'], $recipient['ID'] );
193
194 // Send message into the member's site personal mailbox;
195
196 $aTemplate['Subject'] = process_db_input($aTemplate['Subject'], BX_TAGS_NO_ACTION);
197 $aTemplate['Body'] = process_db_input($aTemplate['Body'], BX_TAGS_NO_ACTION);
198
199 $sender['ID'] = ( !$sender['ID'] ) ? 0 : $sender['ID'] ;
200
201 $sQuery =
202 "
203 INSERT INTO
204 `sys_messages`
205 SET
206 `Date` = NOW(),
207 `Sender` = '{$sender['ID']}',
208 `Recipient` = '{$recipient['ID']}',
209 `Subject` = '{$aTemplate['Subject']}',
210 `Text` = '{$aTemplate['Body']}',
211 `New` = '1',
212 `Type` = 'greeting'
213 ";
214 db_res($sQuery);
215
216 if ( !$mail_ret )
217 {
218 return 10;
219 }
220
221 // Insert kiss into database
222 $kiss_arr = db_arr( "SELECT `ID` FROM `sys_greetings` WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']} LIMIT 1", 0 );
223 if ( !$kiss_arr )
224 $result = db_res( "INSERT INTO `sys_greetings` ( `ID`, `Profile`, `Number`, `When`, `New` ) VALUES ( {$member['ID']}, {$recipient['ID']}, 1, NOW(), '1' )", 0 );
225 else
226 $result = db_res( "UPDATE `sys_greetings` SET `Number` = `Number` + 1, `New` = '1' WHERE `ID` = {$member['ID']} AND `Profile` = {$recipient['ID']}", 0 );
227
228 // If success then perform actions
229 if ( $result )
230 checkAction( $member['ID'], ACTION_ID_SEND_VKISS, true );
231 else
232 return 1;
233
234 return 0;
235}
236
237?>
Note: See TracBrowser for help on using the repository browser.