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 | require_once( './inc/header.inc.php' );
|
---|
24 | require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );
|
---|
25 | require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );
|
---|
26 | require_once( BX_DIRECTORY_PATH_INC . 'match.inc.php' );
|
---|
27 | bx_import('BxDolProfileFields');
|
---|
28 | bx_import('BxDolProfilesController');
|
---|
29 | bx_import('BxTemplFormView');
|
---|
30 | bx_import('BxDolPageView');
|
---|
31 | bx_import('BxDolPrivacy');
|
---|
32 |
|
---|
33 | class BxDolPEditProcessor extends BxDolPageView {
|
---|
34 | var $iProfileID; // id of profile which will be edited
|
---|
35 | var $iArea = 0; // 2=owner, 3=admin, 4=moderator
|
---|
36 | var $bCouple = false; // if we edititng couple profile
|
---|
37 | var $aCoupleMutualFields; // couple mutual fields
|
---|
38 |
|
---|
39 | var $oPC; // object of profiles controller
|
---|
40 | var $oPF; // object of profile fields
|
---|
41 |
|
---|
42 | var $aBlocks; // blocks of page (with items)
|
---|
43 | var $aItems; // all items within blocks
|
---|
44 |
|
---|
45 | var $aProfiles; // array with profiles (couple) data
|
---|
46 | var $aValues; // values
|
---|
47 | var $aOldValues; // values before save
|
---|
48 | var $aErrors; // generated errors
|
---|
49 |
|
---|
50 | var $bAjaxMode; // if the script was called via ajax
|
---|
51 |
|
---|
52 | var $bForceAjaxSave = false;
|
---|
53 |
|
---|
54 | var $aFormPrivacy = array(
|
---|
55 | 'form_attrs' => array(
|
---|
56 | 'id' => 'profile_edit_privacy',
|
---|
57 | 'name' => 'profile_edit_privacy',
|
---|
58 | 'action' => '',
|
---|
59 | 'method' => 'post',
|
---|
60 | 'enctype' => 'multipart/form-data'
|
---|
61 | ),
|
---|
62 | 'params' => array (
|
---|
63 | 'db' => array(
|
---|
64 | 'table' => '',
|
---|
65 | 'key' => '',
|
---|
66 | 'uri' => '',
|
---|
67 | 'uri_title' => '',
|
---|
68 | 'submit_name' => 'save_privacy'
|
---|
69 | ),
|
---|
70 | ),
|
---|
71 | 'inputs' => array (
|
---|
72 | 'profile_id' => array(
|
---|
73 | 'type' => 'hidden',
|
---|
74 | 'name' => 'profile_id',
|
---|
75 | 'value' => 0,
|
---|
76 | ),
|
---|
77 | 'allow_view_to' => array(),
|
---|
78 | 'save_privacy' => array(
|
---|
79 | 'type' => 'submit',
|
---|
80 | 'name' => 'save_privacy',
|
---|
81 | 'value' => '',
|
---|
82 | ),
|
---|
83 | )
|
---|
84 | );
|
---|
85 |
|
---|
86 | function BxDolPEditProcessor() {
|
---|
87 | global $logged;
|
---|
88 |
|
---|
89 | $this -> aProfiles = array( 0 => array(), 1 => array() ); // double arrays (for couples)
|
---|
90 | $this -> aValues = array( 0 => array(), 1 => array() );
|
---|
91 | $this -> aErrors = array( 0 => array(), 1 => array() );
|
---|
92 |
|
---|
93 | $this -> iProfileID = (int)$_REQUEST['ID'];
|
---|
94 |
|
---|
95 | // basic checks
|
---|
96 | if( $logged['member'] ) {
|
---|
97 | $iMemberID = (int)$_COOKIE['memberID'];
|
---|
98 | if( !$this -> iProfileID ) {
|
---|
99 | //if profile id is not set by request, edit own profile
|
---|
100 | $this -> iProfileID = $iMemberID;
|
---|
101 | $this -> iArea = 2;
|
---|
102 | } else {
|
---|
103 | // check if this member is owner
|
---|
104 | if( $this -> iProfileID == $iMemberID )
|
---|
105 | $this -> iArea = 2;
|
---|
106 | }
|
---|
107 | } elseif( $logged['admin'] )
|
---|
108 | $this -> iArea = 3;
|
---|
109 | elseif( $logged['moderator'] )
|
---|
110 | $this -> iArea = 4;
|
---|
111 |
|
---|
112 | $this -> bAjaxMode = ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
|
---|
113 | $this -> bForceAjaxSave = ( isset( $_REQUEST['force_ajax_save'] ) and $_REQUEST['force_ajax_save'] );
|
---|
114 |
|
---|
115 | $this->aFormPrivacy['form_attrs']['action'] = $_SERVER['PHP_SELF'];
|
---|
116 | $this->aFormPrivacy['inputs']['profile_id']['value'] = $this->iProfileID;
|
---|
117 | $this->aFormPrivacy['inputs']['save_privacy']['value'] = _t('_edit_profile_privacy_save');
|
---|
118 |
|
---|
119 | parent::BxDolPageView('pedit');
|
---|
120 | }
|
---|
121 |
|
---|
122 | function getBlockCode_Info() {
|
---|
123 | if( !$this -> iProfileID )
|
---|
124 | return _t( '_Profile not specified' );
|
---|
125 |
|
---|
126 | if( !$this -> iArea )
|
---|
127 | return _t( '_You cannot edit this profile' );
|
---|
128 |
|
---|
129 | /* @var $this->oPC BxDolProfilesController */
|
---|
130 | $this -> oPC = new BxDolProfilesController();
|
---|
131 |
|
---|
132 | //get profile info array
|
---|
133 | $this -> aProfiles[0] = $this -> oPC -> getProfileInfo( $this -> iProfileID );
|
---|
134 | if( !$this -> aProfiles[0] )
|
---|
135 | return _t( '_Profile not found' );
|
---|
136 |
|
---|
137 | if( $this -> aProfiles[0]['Couple'] ) { // load couple profile
|
---|
138 | $this -> aProfiles[1] = $this -> oPC -> getProfileInfo( $this -> aProfiles[0]['Couple'] );
|
---|
139 |
|
---|
140 | if( !$this -> aProfiles[1] )
|
---|
141 | return _t( '_Couple profile not found' );
|
---|
142 |
|
---|
143 | $this -> bCouple = true; //couple enabled
|
---|
144 | }
|
---|
145 |
|
---|
146 | /* @var $this->oPF BxDolProfileFields */
|
---|
147 | $this -> oPF = new BxDolProfileFields( $this -> iArea );
|
---|
148 | if( !$this -> oPF -> aArea )
|
---|
149 | return 'Profile Fields cache not loaded. Cannot continue.';
|
---|
150 |
|
---|
151 | $this -> aCoupleMutualFields = $this -> oPF -> getCoupleMutualFields();
|
---|
152 |
|
---|
153 | //collect blocks
|
---|
154 | $this -> aBlocks = $this -> oPF -> aArea;
|
---|
155 |
|
---|
156 | //collect items
|
---|
157 | $this -> aItems = array();
|
---|
158 | foreach ($this -> aBlocks as $aBlock) {
|
---|
159 | foreach( $aBlock['Items'] as $iItemID => $aItem )
|
---|
160 | $this -> aItems[$iItemID] = $aItem;
|
---|
161 | }
|
---|
162 |
|
---|
163 | $this -> aValues[0] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[0] ); // set default values
|
---|
164 | if( $this -> bCouple )
|
---|
165 | $this -> aValues[1] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[1] ); // set default values
|
---|
166 |
|
---|
167 | $this -> aOldValues = $this -> aValues;
|
---|
168 |
|
---|
169 | $sStatusText = '';
|
---|
170 | if( isset($_POST['do_submit']) ) {
|
---|
171 | $this -> oPF -> processPostValues( $this -> bCouple, $this -> aValues, $this -> aErrors, 0, $this -> iProfileID, (int)$_REQUEST['pf_block'] );
|
---|
172 |
|
---|
173 | if( empty( $this -> aErrors[0] ) and empty( $this -> aErrors[1] ) ) { // do not save in ajax mode
|
---|
174 | if (!$this -> bAjaxMode or $this->bForceAjaxSave) {
|
---|
175 | $this -> saveProfile();
|
---|
176 | $sStatusText = '_Save profile successful';
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | if($this -> bAjaxMode) {
|
---|
182 | $this -> showErrorsJson();
|
---|
183 | exit;
|
---|
184 | } else
|
---|
185 | return $this -> showEditForm($sStatusText);
|
---|
186 | }
|
---|
187 | function getBlockCode_Privacy() {
|
---|
188 | $oPrivacy = new BxDolPrivacy('sys_page_compose_privacy', 'id', 'user_id');
|
---|
189 | $this->aFormPrivacy['inputs']['allow_view_to'] = $oPrivacy->getGroupChooser(getLoggedId(), 'profile', 'view');
|
---|
190 | $this->aFormPrivacy['inputs']['allow_view_to']['value'] = (string)$this -> aProfiles[0]['allow_view_to'];
|
---|
191 |
|
---|
192 | $oForm = new BxTemplFormView($this->aFormPrivacy);
|
---|
193 | $oForm->initChecker();
|
---|
194 |
|
---|
195 | if($oForm->isSubmittedAndValid()) {
|
---|
196 | $iProfileId = (int)$_REQUEST['profile_id'];
|
---|
197 | $iAllowViewTo = (int)$_REQUEST['allow_view_to'];
|
---|
198 |
|
---|
199 | if((int)db_res("UPDATE `Profiles` SET `allow_view_to`='" . $iAllowViewTo . "' WHERE `ID`='" . $iProfileId . "' LIMIT 1") > 0)
|
---|
200 | $sStatusText = '_Save profile successful';
|
---|
201 | }
|
---|
202 |
|
---|
203 | if($sStatusText)
|
---|
204 | $sStatusText = MsgBox(_t($sStatusText), 3);
|
---|
205 |
|
---|
206 | return $sStatusText . $oForm->getCode();
|
---|
207 | }
|
---|
208 |
|
---|
209 | function showErrorsJson() {
|
---|
210 | header('Content-Type:text/javascript');
|
---|
211 |
|
---|
212 | echo $this -> oPF -> genJsonErrors( $this -> aErrors, $this -> bCouple );
|
---|
213 | }
|
---|
214 |
|
---|
215 | function showEditForm( $sStatusText ) {
|
---|
216 | $aEditFormParams = array(
|
---|
217 | 'couple_enabled' => $this->bCouple,
|
---|
218 | 'couple' => $this->bCouple,
|
---|
219 | 'page' => $this->iPage,
|
---|
220 | 'hiddens' => array('ID' => $this -> iProfileID, 'do_submit' => '1'), //$this->genHiddenFieldsArray(),
|
---|
221 | 'errors' => $this->aErrors,
|
---|
222 | 'values' => $this->aValues,
|
---|
223 | 'profile_id' => $this->iProfileID,
|
---|
224 | );
|
---|
225 |
|
---|
226 | if($sStatusText)
|
---|
227 | $sStatusText = MsgBox(_t($sStatusText), 3);
|
---|
228 |
|
---|
229 | return $sStatusText . $this->oPF->getFormCode($aEditFormParams);
|
---|
230 | }
|
---|
231 |
|
---|
232 | function saveProfile() {
|
---|
233 | $aProfileInfo = db_arr("SELECT * FROM `Profiles` WHERE `ID` = {$this -> iProfileID}");
|
---|
234 | $aDiff = $this -> getDiffValues(0);
|
---|
235 | $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
|
---|
236 |
|
---|
237 | $aUpd['DateLastEdit'] = date( 'Y-m-d H:i:s' );
|
---|
238 | if( !getParam('autoApproval_ifProfile') && $this -> iArea == 2 )
|
---|
239 | $aUpd['Status'] = 'Approval';
|
---|
240 |
|
---|
241 | if( ( $this -> iArea == 3 or $this -> iArea == 4 ) and isset( $_POST['doSetMembership'] ) and $_POST['doSetMembership'] == 'yes' )
|
---|
242 | $this -> setMembership();
|
---|
243 |
|
---|
244 | $this -> oPC -> updateProfile( $this -> iProfileID, $aUpd );
|
---|
245 |
|
---|
246 | // create system event
|
---|
247 | require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php');
|
---|
248 | $oZ = new BxDolAlerts('profile', 'edit', $this -> iProfileID, 0, array('OldProfileInfo' => $aProfileInfo) );
|
---|
249 | $oZ->alert();
|
---|
250 |
|
---|
251 | if( $this -> bCouple ) {
|
---|
252 | $aDiff = $this -> getDiffValues(1);
|
---|
253 | $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
|
---|
254 |
|
---|
255 | $aUpd['DateLastEdit'] = date( 'Y-m-d H:i:s' );
|
---|
256 | if( !getParam('autoApproval_ifProfile') && $this -> iArea == 2 )
|
---|
257 | $aUpd['Status'] = 'Approval';
|
---|
258 |
|
---|
259 | $this -> oPC -> updateProfile( $this -> aProfiles[0]['Couple'], $aUpd );
|
---|
260 | }
|
---|
261 |
|
---|
262 | }
|
---|
263 |
|
---|
264 | function setMembership() {
|
---|
265 | $iMshipID = (int)$_POST['MembershipID'];
|
---|
266 | $iMshipDays = (int)$_POST['MembershipDays']; // 0 = unlim
|
---|
267 | $bStartsNow = ($_POST['MembershipImmediately'] == 'on');
|
---|
268 | return setMembership( $this -> iProfileID, $iMshipID, $iMshipDays, $bStartsNow );
|
---|
269 | }
|
---|
270 |
|
---|
271 | function getDiffValues($iInd) {
|
---|
272 | $aOld = $this -> aOldValues[$iInd];
|
---|
273 | $aNew = $this -> aValues[$iInd];
|
---|
274 |
|
---|
275 | $aDiff = array();
|
---|
276 | foreach( $aNew as $sName => $mNew ){
|
---|
277 | $mOld = $aOld[$sName];
|
---|
278 |
|
---|
279 | if( is_array($mNew) ) {
|
---|
280 | if( count($mNew) == count($mOld) ) {
|
---|
281 | //compare each value
|
---|
282 | $mOldS = $mOld;
|
---|
283 | $mNewS = $mNew;
|
---|
284 | sort( $mOldS ); //sort them for correct comparison
|
---|
285 | sort( $mNewS );
|
---|
286 |
|
---|
287 | foreach( $mNewS as $iKey => $sVal )
|
---|
288 | if( $mNewS[$iKey] != $mOld[$iKey] ) {
|
---|
289 | $aDiff[$sName] = $mNew; //found difference
|
---|
290 | break;
|
---|
291 | }
|
---|
292 | } else
|
---|
293 | $aDiff[$sName] = $mNew;
|
---|
294 | } else {
|
---|
295 | if( $mNew != $mOld )
|
---|
296 | $aDiff[$sName] = $mNew;
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | return $aDiff;
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | $_page['name_index'] = 25;
|
---|
305 | $_page['css_name'] = 'pedit.css';
|
---|
306 | $_page['extra_js'] .= '<script type="text/javascript" language="JavaScript" src="' . $site['plugins'] . 'jquery/jquery.form.js"></script>';
|
---|
307 | $_page['extra_js'] .= '<script type="text/javascript" language="JavaScript" src="inc/js/pedit.js"></script>';
|
---|
308 |
|
---|
309 | check_logged();
|
---|
310 |
|
---|
311 | $_page['header'] = _t( '_Edit Profile' );
|
---|
312 | $_page['header_text'] = _t( '_Edit Profile' );
|
---|
313 | $_ni = $_page['name_index'];
|
---|
314 |
|
---|
315 |
|
---|
316 | $oEditProc = new BxDolPEditProcessor();
|
---|
317 | $_page_cont[$_ni]['page_main_code'] = $oEditProc->getCode();
|
---|
318 | PageCode();
|
---|
319 | ?> |
---|