1 | <?php
|
---|
2 |
|
---|
3 | /***************************************************************************
|
---|
4 | * Dolphin Smart Community Builder
|
---|
5 | * -------------------
|
---|
6 | * begin : Mon Mar 23 2006
|
---|
7 | * copyright : (C) 2007 BoonEx Group
|
---|
8 | * website : http://www.boonex.com
|
---|
9 | * This file is part of Dolphin - Smart Community Builder
|
---|
10 | *
|
---|
11 | * Dolphin is free software; you can redistribute it and/or modify it under
|
---|
12 | * the terms of the GNU General Public License as published by the
|
---|
13 | * Free Software Foundation; either version 2 of the
|
---|
14 | * License, or any later version.
|
---|
15 | *
|
---|
16 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
---|
17 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
18 | * See the GNU General Public License for more details.
|
---|
19 | * You should have received a copy of the GNU General Public License along with Dolphin,
|
---|
20 | * see license.txt file; if not, write to marketing@boonex.com
|
---|
21 | ***************************************************************************/
|
---|
22 |
|
---|
23 | define('BX_INDEX_PAGE', 1);
|
---|
24 |
|
---|
25 | require_once( './inc/header.inc.php' );
|
---|
26 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
|
---|
27 | require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );
|
---|
28 | require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );
|
---|
29 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolPageView.php' );
|
---|
30 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolProfileFields.php' );
|
---|
31 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolProfilesController.php' );
|
---|
32 | require_once( BX_DIRECTORY_PATH_ROOT . "templates/tmpl_{$tmpl}/scripts/BxTemplFormView.php" );
|
---|
33 |
|
---|
34 | $GLOBALS['oSysTemplate']->addJsTranslation('_Errors in join form');
|
---|
35 |
|
---|
36 | class BxDolJoinPageView extends BxDolPageView {
|
---|
37 | function BxDolJoinPageView() {
|
---|
38 | parent::BxDolPageView('join');
|
---|
39 | }
|
---|
40 |
|
---|
41 | function getBlockCode_JoinForm() {
|
---|
42 | $oJoinProc = new BxDolJoinProcessor();
|
---|
43 | return $oJoinProc->process();
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | class BxDolJoinProcessor {
|
---|
49 |
|
---|
50 | var $oPF; //profile fields
|
---|
51 | var $iPage; //currently shown page
|
---|
52 | var $aPages; //available pages
|
---|
53 | var $aValues; //inputted values
|
---|
54 | var $aErrors; //errors generated on page
|
---|
55 | var $bAjaxMode; // defines if the script were requested by ajax
|
---|
56 |
|
---|
57 | var $bCoupleEnabled;
|
---|
58 | var $bCouple;
|
---|
59 |
|
---|
60 | function BxDolJoinProcessor() {
|
---|
61 | $this -> aErrors = array( 0 => array(), 1 => array() );
|
---|
62 |
|
---|
63 | $this -> oPF = new BxDolProfileFields(1);
|
---|
64 |
|
---|
65 | $this -> aValues = array();
|
---|
66 | $this -> aValues[0] = $this -> aValues[1] = $this -> oPF -> getDefaultValues();// double arrays (for couples)
|
---|
67 |
|
---|
68 | $this -> bAjaxMode = ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
|
---|
69 | }
|
---|
70 |
|
---|
71 | function process() {
|
---|
72 | if( !$this -> oPF -> aArea )
|
---|
73 | return 'Profile Fields cache not loaded. Cannot continue.';
|
---|
74 |
|
---|
75 | $this -> aPages = array_keys( $this -> oPF -> aArea );
|
---|
76 |
|
---|
77 | $this -> iPage = ( isset( $_POST['join_page'] ) ) ? $_POST['join_page'] : 0; // get current working page from POST
|
---|
78 |
|
---|
79 | if( $this -> iPage !== 'done' )
|
---|
80 | $this -> iPage = (int)$this -> iPage;
|
---|
81 |
|
---|
82 | $this -> getCoupleOptions();
|
---|
83 |
|
---|
84 | $this -> processPostValues();
|
---|
85 |
|
---|
86 | if( $this -> bAjaxMode ) {
|
---|
87 | $this -> showErrorsJson();
|
---|
88 | exit;
|
---|
89 | } else {
|
---|
90 | ob_start();
|
---|
91 |
|
---|
92 | if( $this -> iPage === 'done' ) { //if all pages are finished and no errors found
|
---|
93 | list( $iMemID, $sStatus ) = $this -> registerMember();
|
---|
94 |
|
---|
95 | if( !$iMemID )
|
---|
96 | $this -> showFailPage();
|
---|
97 | else
|
---|
98 | $this -> showFinishPage( $iMemID, $sStatus );
|
---|
99 | } else
|
---|
100 | $this -> showJoinForm();
|
---|
101 |
|
---|
102 | return ob_get_clean();
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | function getCoupleOptions() {
|
---|
107 | //find Couple item (check if it is active)
|
---|
108 | $aCoupleItem = false;
|
---|
109 | foreach ($this -> aPages as $iPageInd => $iPage) { //cycle pages
|
---|
110 | $aBlocks = $this -> oPF -> aArea[ $iPage ];
|
---|
111 | foreach ($aBlocks as $iBlockID => $aBlock) { //cycle blocks
|
---|
112 | $aItems = $aBlock['Items'];
|
---|
113 | foreach ($aItems as $iItemID => $aItem) { //cycle items
|
---|
114 | if( $aItem['Name'] == 'Couple' ) { // we found it!
|
---|
115 | $aCoupleItem = $aItem;
|
---|
116 | break;
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | if( $aCoupleItem ) // we already found it
|
---|
121 | break;
|
---|
122 | }
|
---|
123 |
|
---|
124 | if( $aCoupleItem ) // we already found it
|
---|
125 | break;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if( $aCoupleItem ) {
|
---|
129 | $this -> bCoupleEnabled = true;
|
---|
130 | $this -> bCouple = ( isset( $_REQUEST['Couple'] ) and $_REQUEST['Couple'] == 'yes' ) ? true : false;
|
---|
131 | } else {
|
---|
132 | $this -> bCoupleEnabled = false;
|
---|
133 | $this -> bCouple = false;
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | function processPostValues() {
|
---|
138 |
|
---|
139 | foreach ($this -> aPages as $iPage) { //cycle pages
|
---|
140 |
|
---|
141 | if( $this -> iPage !== 'done' and $iPage >= $this -> iPage ) {
|
---|
142 | $this -> iPage = $iPage; // we are on the current page. dont process these values, dont go further, just show form.
|
---|
143 | break;
|
---|
144 | }
|
---|
145 |
|
---|
146 | // process post values by Profile Fields class
|
---|
147 | $this -> oPF -> processPostValues( $this -> bCouple, $this -> aValues, $this -> aErrors, $iPage );
|
---|
148 |
|
---|
149 | if( !empty( $this -> aErrors[0] ) or ( $this -> bCouple and !empty( $this -> aErrors[1] ) ) ) { //we found errors on previous page
|
---|
150 | // do not process further values, just go to erroneous page.
|
---|
151 | $this -> iPage = $iPage;
|
---|
152 | break;
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | function showErrorsJson() {
|
---|
158 | header('Content-Type:text/javascript');
|
---|
159 |
|
---|
160 | echo $this -> oPF -> genJsonErrors( $this -> aErrors, $this -> bCouple );
|
---|
161 | }
|
---|
162 |
|
---|
163 | function showJoinForm() {
|
---|
164 |
|
---|
165 | $aJoinFormParams = array(
|
---|
166 | 'couple_enabled' => $this->bCoupleEnabled,
|
---|
167 | 'couple' => $this->bCouple,
|
---|
168 | 'page' => $this->iPage,
|
---|
169 | 'hiddens' => $this->genHiddenFieldsArray(),
|
---|
170 | 'errors' => $this->aErrors,
|
---|
171 | 'values' => $this->aValues,
|
---|
172 | );
|
---|
173 | //echoDbg($this -> oPF);
|
---|
174 | echo $this->oPF->getFormCode($aJoinFormParams);
|
---|
175 | }
|
---|
176 |
|
---|
177 | function genHiddenFieldsArray() {
|
---|
178 | $aHiddenFields = array();
|
---|
179 |
|
---|
180 | //retrieve next page
|
---|
181 | $iPageInd = (int)array_search( $this -> iPage, $this -> aPages );
|
---|
182 | $iNextInd = $iPageInd + 1;
|
---|
183 |
|
---|
184 | if( array_key_exists( $iNextInd, $this -> aPages ) )
|
---|
185 | $sNextPage = $this -> aPages[ $iNextInd ];
|
---|
186 | else
|
---|
187 | $sNextPage = 'done';
|
---|
188 |
|
---|
189 | // insert next page
|
---|
190 | $aHiddenFields['join_page'] = $sNextPage;
|
---|
191 |
|
---|
192 | //echoDbg( $this -> aValues );
|
---|
193 |
|
---|
194 | // insert entered values
|
---|
195 | $iHumans = $this -> bCouple ? 2 : 1;
|
---|
196 | for( $iHuman = 0; $iHuman < $iHumans; $iHuman ++ ) {
|
---|
197 | foreach( $this -> aPages as $iPage ) {
|
---|
198 | if( $iPage == $this -> iPage )
|
---|
199 | break; // we are on this page
|
---|
200 |
|
---|
201 | $aBlocks = $this -> oPF -> aArea[ $iPage ];
|
---|
202 | foreach( $aBlocks as $aBlock ) {
|
---|
203 | foreach( $aBlock['Items'] as $aItem ) {
|
---|
204 | $sItemName = $aItem['Name'];
|
---|
205 |
|
---|
206 | if( isset( $this -> aValues[$iHuman][ $sItemName ] ) ) {
|
---|
207 | $mValue = $this -> aValues[$iHuman][ $sItemName ];
|
---|
208 |
|
---|
209 | switch( $aItem['Type'] ) {
|
---|
210 | case 'pass':
|
---|
211 | $aHiddenFields[ $sItemName . '_confirm[' . $iHuman . ']' ] = $mValue;
|
---|
212 | case 'text':
|
---|
213 | case 'area':
|
---|
214 | case 'html_area':
|
---|
215 | case 'date':
|
---|
216 | case 'datetime':
|
---|
217 | case 'select_one':
|
---|
218 | case 'num':
|
---|
219 | $aHiddenFields[ $sItemName . '[' . $iHuman . ']' ] = $mValue;
|
---|
220 | break;
|
---|
221 |
|
---|
222 | case 'select_set':
|
---|
223 | foreach( $mValue as $iInd => $sValue )
|
---|
224 | $aHiddenFields[ $sItemName . '[' . $iHuman . '][' . $iInd . ']' ] = $sValue;
|
---|
225 | break;
|
---|
226 |
|
---|
227 | case 'range':
|
---|
228 | $aHiddenFields[ $sItemName . '[' . $iHuman . '][0]' ] = $mValue[0];
|
---|
229 | $aHiddenFields[ $sItemName . '[' . $iHuman . '][1]' ] = $mValue[1];
|
---|
230 | break;
|
---|
231 |
|
---|
232 | case 'bool':
|
---|
233 | $aHiddenFields[ $sItemName . '[' . $iHuman . ']' ] = $mValue ? 'yes' : '';
|
---|
234 | break;
|
---|
235 |
|
---|
236 | case 'system':
|
---|
237 | switch( $aItem['Name'] ) {
|
---|
238 | case 'Couple':
|
---|
239 | case 'TermsOfUse':
|
---|
240 | $aHiddenFields[ $sItemName ] = $mValue ? 'yes' : '';
|
---|
241 | break;
|
---|
242 |
|
---|
243 | case 'Captcha':
|
---|
244 | $aHiddenFields[ $sItemName ] = $mValue;
|
---|
245 | break;
|
---|
246 |
|
---|
247 | case 'ProfilePhoto':
|
---|
248 | $aHiddenFields['ProfilePhoto_tmp'] = $mValue;
|
---|
249 | break;
|
---|
250 | }
|
---|
251 | break;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | }
|
---|
255 | }
|
---|
256 | }
|
---|
257 | }
|
---|
258 | return $aHiddenFields;
|
---|
259 | }
|
---|
260 |
|
---|
261 | function registerMember() {
|
---|
262 | $oPC = new BxDolProfilesController();
|
---|
263 |
|
---|
264 | require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php');
|
---|
265 | $oZ = new BxDolAlerts('profile', 'before_join', 0, 0, $this->aValues[0]);
|
---|
266 | $oZ->alert();
|
---|
267 |
|
---|
268 | $aProfile1 = $this->oPF->getProfileFromValues($this->aValues[0]);
|
---|
269 | list($iId1, $sStatus1) = $oPC->createProfile($aProfile1);
|
---|
270 |
|
---|
271 | //--- check whether profile was created successfully or not
|
---|
272 | if(!$iId1) {
|
---|
273 | if(isset($aProfile1['ProfilePhoto']) && !empty($aProfile1['ProfilePhoto']))
|
---|
274 | @unlink($GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto']);
|
---|
275 |
|
---|
276 | return array(false, 'Fail');
|
---|
277 | }
|
---|
278 |
|
---|
279 | //--- check for couple profile
|
---|
280 | if($this->bCouple) {
|
---|
281 | $aProfile2 = $this->oPF->getProfileFromValues($this -> aValues[1]);
|
---|
282 | list($iId2, $sStatus2) = $oPC->createProfile($aProfile2, false, $iId1);
|
---|
283 |
|
---|
284 | if(!$iId2) {
|
---|
285 | $oPC->deleteProfile($iId1);
|
---|
286 | return array(false, 'Fail');
|
---|
287 | }
|
---|
288 | }
|
---|
289 |
|
---|
290 | //--- upload profile photo
|
---|
291 | if(isset($aProfile1['ProfilePhoto']) && !empty($aProfile1['ProfilePhoto'])) {
|
---|
292 | $sPass1 = getPassword($iId1);
|
---|
293 | bx_login($iId1);
|
---|
294 |
|
---|
295 | check_logged();
|
---|
296 |
|
---|
297 | BxDolService::call('avatar', 'set_image_for_cropping', array ($iId1, $GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto']));
|
---|
298 |
|
---|
299 | if (BxDolRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader')) {
|
---|
300 | $aFileInfo = array (
|
---|
301 | 'medTitle' => _t('_bx_ava_avatar'),
|
---|
302 | 'medDesc' => _t('_bx_ava_avatar'),
|
---|
303 | 'medTags' => _t('_ProfilePhotos'),
|
---|
304 | 'Categories' => array(_t('_ProfilePhotos')),
|
---|
305 | 'album' => str_replace('{nickname}', getNickName($iId1), getParam('bx_photos_profile_album_name')),
|
---|
306 | );
|
---|
307 | BxDolService::call('photos', 'perform_photo_upload', array($GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto'], $aFileInfo, false), 'Uploader');
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | //--- create system event
|
---|
312 | bx_import('BxDolAlerts');
|
---|
313 | $oZ = new BxDolAlerts('profile', 'join', $iId1);
|
---|
314 | $oZ->alert();
|
---|
315 |
|
---|
316 | return array($iId1, $sStatus1);
|
---|
317 | }
|
---|
318 |
|
---|
319 | function showFailPage() {
|
---|
320 | echo '<div class="dbContentHtml">';
|
---|
321 | echo _t( '_Join failed' );
|
---|
322 | echo '</div>';
|
---|
323 | }
|
---|
324 |
|
---|
325 | function showFinishPage( $iMemID, $sStatus ) {
|
---|
326 |
|
---|
327 | switch( $sStatus ) {
|
---|
328 | case 'Active': $sStatusText = ('_USER_ACTIVATION_SUCCEEDED'); break; //activated automatically
|
---|
329 | case 'Approval': $sStatusText = ('_USER_CONF_SUCCEEDED'); break; //automatically confirmed
|
---|
330 | case 'Unconfirmed': $sStatusText = ('_EMAIL_CONF_SENT'); break; //conf mail succesfully sent
|
---|
331 | case 'NotSent': $sStatusText = ('_EMAIL_CONF_NOT_SENT'); break; //failed to send conf mail
|
---|
332 | }
|
---|
333 |
|
---|
334 | if ('EXIT' == BxDolService::call('avatar', 'join', array ($iMemID, $sStatusText))) {
|
---|
335 | exit;
|
---|
336 | }
|
---|
337 |
|
---|
338 | echo '<div class="dbContentHtml">';
|
---|
339 | echo _t( '_Join complete' );
|
---|
340 | echo '<br />';
|
---|
341 | echo _t( $sStatusText );
|
---|
342 | echo '</div>';
|
---|
343 | }
|
---|
344 |
|
---|
345 | }
|
---|
346 |
|
---|
347 |
|
---|
348 | check_logged();
|
---|
349 |
|
---|
350 | $_page['header'] = _t( '_JOIN_H' );
|
---|
351 | $_page['header_text'] = _t( '_JOIN_H' );
|
---|
352 |
|
---|
353 | if( $logged['member'] )
|
---|
354 | {
|
---|
355 | $_page['name_index'] = 0;
|
---|
356 | $_page_cont[0]['page_main_code'] = _t( '_Sorry, you\'re already joined' );
|
---|
357 | PageCode();
|
---|
358 | exit;
|
---|
359 | }
|
---|
360 |
|
---|
361 | if ( getParam('reg_by_inv_only') == 'on' && getID($_COOKIE['idFriend'])==0 ) {
|
---|
362 | $_page['name_index'] = 0;
|
---|
363 | $_page_cont[0]['page_main_code'] = MsgBox(_t('_registration by invitation only'));
|
---|
364 | PageCode();
|
---|
365 | exit;
|
---|
366 | }
|
---|
367 |
|
---|
368 | $_page['name_index'] = 81;
|
---|
369 | $_page['css_name'] = 'join.css';
|
---|
370 | $_ni = $_page['name_index'];
|
---|
371 |
|
---|
372 | $oJoinView = new BxDolJoinPageView();
|
---|
373 | $_page_cont[$_ni]['page_main_code'] = $oJoinView->getCode();
|
---|
374 |
|
---|
375 | $oSysTemplate->addJs(array('join.js', 'jquery.form.js'));
|
---|
376 | PageCode();
|
---|
377 |
|
---|