| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | require_once( './inc/header.inc.php' );
|
|---|
| 4 | require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );
|
|---|
| 5 | require_once( BX_DIRECTORY_PATH_INC . 'db.inc.php' );
|
|---|
| 6 | require_once( BX_DIRECTORY_PATH_INC . 'match.inc.php' );
|
|---|
| 7 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolProfileFields.php' );
|
|---|
| 8 | require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolProfilesController.php' );
|
|---|
| 9 | require_once( BX_DIRECTORY_PATH_ROOT . "templates/tmpl_{$tmpl}/scripts/BxTemplFormView.php" );
|
|---|
| 10 |
|
|---|
| 11 | $_page['name_index'] = 25;
|
|---|
| 12 | $_page['css_name'] = 'pedit.css';
|
|---|
| 13 | //$_page['extra_js'] = '<script type="text/javascript" language="JavaScript" src="' . $site['plugins'] . 'jquery/jquery.js"></script>';
|
|---|
| 14 | $_page['extra_js'] .= '<script type="text/javascript" language="JavaScript" src="' . $site['plugins'] . 'jquery/ui.datepicker.js"></script>';
|
|---|
| 15 | $_page['extra_js'] .= '<script type="text/javascript" language="JavaScript" src="' . $site['plugins'] . 'jquery/jquery.form.js"></script>';
|
|---|
| 16 | $_page['extra_js'] .= '<script type="text/javascript" language="JavaScript" src="inc/js/pedit.js"></script>';
|
|---|
| 17 |
|
|---|
| 18 | //init datepicker
|
|---|
| 19 | $iMinAge = (int)getParam( 'search_start_age' );
|
|---|
| 20 | $iMaxAge = (int)getParam( 'search_end_age' );
|
|---|
| 21 | $iCurYear = (int)date('Y');
|
|---|
| 22 | $iMinYear = $iCurYear - $iMaxAge - 1;
|
|---|
| 23 | $iMaxYear = $iCurYear - $iMinAge;
|
|---|
| 24 | $iSelectedRel = ceil( $iMinAge * 365.25 ); //get relative days number for default date
|
|---|
| 25 |
|
|---|
| 26 | $sDatepickerInit = $oTemplConfig -> customize['join']['datepickerInit'];
|
|---|
| 27 |
|
|---|
| 28 | $sDatepickerInit = str_replace( '{min_year}', $iMinYear, $sDatepickerInit );
|
|---|
| 29 | $sDatepickerInit = str_replace( '{max_year}', $iMaxYear, $sDatepickerInit );
|
|---|
| 30 | $sDatepickerInit = str_replace( '{dfl_days}', $iSelectedRel, $sDatepickerInit );
|
|---|
| 31 |
|
|---|
| 32 | $_page['extra_js'] .= '
|
|---|
| 33 | <script type="text/javascript" language="JavaScript">
|
|---|
| 34 | $( document ).ready( function(){
|
|---|
| 35 | ' . $sDatepickerInit . '
|
|---|
| 36 | } );
|
|---|
| 37 | </script>';
|
|---|
| 38 |
|
|---|
| 39 | check_logged();
|
|---|
| 40 |
|
|---|
| 41 | $_page['header'] = _t( '_Edit Profile' );
|
|---|
| 42 | $_page['header_text'] = _t( '_Edit Profile' );
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | $oEditProc = new BxDolPEditProcessor();
|
|---|
| 47 |
|
|---|
| 48 | $_ni = $_page['name_index'];
|
|---|
| 49 | $_page_cont[$_ni]['page_main_code'] = $oEditProc -> process();
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | PageCode();
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | class BxDolPEditProcessor {
|
|---|
| 57 | var $iProfileID; // id of profile which will be edited
|
|---|
| 58 | var $iArea = 0; // 2=owner, 3=admin, 4=moderator
|
|---|
| 59 | var $bCouple = false; // if we edititng couple profile
|
|---|
| 60 | var $aCoupleMutualFields; // couple mutual fields
|
|---|
| 61 |
|
|---|
| 62 | var $oPC; // object of profiles controller
|
|---|
| 63 | var $oPF; // object of profile fields
|
|---|
| 64 |
|
|---|
| 65 | var $aBlocks; // blocks of page (with items)
|
|---|
| 66 | var $aItems; // all items within blocks
|
|---|
| 67 |
|
|---|
| 68 | var $aProfiles; // array with profiles (couple) data
|
|---|
| 69 | var $aValues; // values
|
|---|
| 70 | var $aOldValues; // values before save
|
|---|
| 71 | var $aErrors; // generated errors
|
|---|
| 72 |
|
|---|
| 73 | var $bAjaxMode; // if the script was called via ajax
|
|---|
| 74 |
|
|---|
| 75 | function BxDolPEditProcessor() {
|
|---|
| 76 | global $logged;
|
|---|
| 77 |
|
|---|
| 78 | $this -> aProfiles = array( 0 => array(), 1 => array() ); // double arrays (for couples)
|
|---|
| 79 | $this -> aValues = array( 0 => array(), 1 => array() );
|
|---|
| 80 | $this -> aErrors = array( 0 => array(), 1 => array() );
|
|---|
| 81 |
|
|---|
| 82 | $this -> iProfileID = (int)$_REQUEST['ID'];
|
|---|
| 83 |
|
|---|
| 84 | // basic checks
|
|---|
| 85 | if( $logged['member'] ) {
|
|---|
| 86 | $iMemberID = (int)$_COOKIE['memberID'];
|
|---|
| 87 | if( !$this -> iProfileID ) {
|
|---|
| 88 | //if profile id is not set by request, edit own profile
|
|---|
| 89 | $this -> iProfileID = $iMemberID;
|
|---|
| 90 | $this -> iArea = 2;
|
|---|
| 91 | } else {
|
|---|
| 92 | // check if this member is owner
|
|---|
| 93 | if( $this -> iProfileID == $iMemberID )
|
|---|
| 94 | $this -> iArea = 2;
|
|---|
| 95 | }
|
|---|
| 96 | } elseif( $logged['admin'] )
|
|---|
| 97 | $this -> iArea = 3;
|
|---|
| 98 | elseif( $logged['moderator'] )
|
|---|
| 99 | $this -> iArea = 4;
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | $this -> bAjaxMode = ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | function process() {
|
|---|
| 106 | if( !$this -> iProfileID )
|
|---|
| 107 | return _t( '_Profile not specified' );
|
|---|
| 108 |
|
|---|
| 109 | if( !$this -> iArea )
|
|---|
| 110 | return _t( '_You cannot edit this profile' );
|
|---|
| 111 |
|
|---|
| 112 | /* @var $this->oPC BxDolProfilesController */
|
|---|
| 113 | $this -> oPC = new BxDolProfilesController();
|
|---|
| 114 |
|
|---|
| 115 | //get profile info array
|
|---|
| 116 | $this -> aProfiles[0] = $this -> oPC -> getProfileInfo( $this -> iProfileID );
|
|---|
| 117 | if( !$this -> aProfiles[0] )
|
|---|
| 118 | return _t( '_Profile not found' );
|
|---|
| 119 |
|
|---|
| 120 | if( $this -> aProfiles[0]['Couple'] ) { // load couple profile
|
|---|
| 121 | $this -> aProfiles[1] = $this -> oPC -> getProfileInfo( $this -> aProfiles[0]['Couple'] );
|
|---|
| 122 |
|
|---|
| 123 | if( !$this -> aProfiles[1] )
|
|---|
| 124 | return _t( '_Couple profile not found' );
|
|---|
| 125 |
|
|---|
| 126 | $this -> bCouple = true; //couple enabled
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /* @var $this->oPF BxDolProfileFields */
|
|---|
| 130 | $this -> oPF = new BxDolProfileFields( $this -> iArea );
|
|---|
| 131 | if( !$this -> oPF -> aArea )
|
|---|
| 132 | return 'Profile Fields cache not loaded. Cannot continue.';
|
|---|
| 133 |
|
|---|
| 134 | $this -> aCoupleMutualFields = $this -> oPF -> getCoupleMutualFields();
|
|---|
| 135 |
|
|---|
| 136 | //collect blocks
|
|---|
| 137 | $this -> aBlocks = $this -> oPF -> aArea;
|
|---|
| 138 |
|
|---|
| 139 | //collect items
|
|---|
| 140 | $this -> aItems = array();
|
|---|
| 141 | foreach ($this -> aBlocks as $aBlock) {
|
|---|
| 142 | foreach( $aBlock['Items'] as $iItemID => $aItem )
|
|---|
| 143 | $this -> aItems[$iItemID] = $aItem;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | $this -> aValues[0] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[0] ); // set default values
|
|---|
| 147 | if( $this -> bCouple )
|
|---|
| 148 | $this -> aValues[1] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[1] ); // set default values
|
|---|
| 149 |
|
|---|
| 150 | $this -> aOldValues = $this -> aValues;
|
|---|
| 151 |
|
|---|
| 152 | $sStatusText = '';
|
|---|
| 153 | if( isset($_POST['do_submit']) ) {
|
|---|
| 154 | $this -> oPF -> processPostValues( $this -> bCouple, $this -> aValues, $this -> aErrors, 0, $this -> iProfileID );
|
|---|
| 155 |
|
|---|
| 156 | if( empty( $this -> aErrors[0] ) and empty( $this -> aErrors[1] ) and !$this -> bAjaxMode ) { // do not save in ajax mode
|
|---|
| 157 | $this -> saveProfile();
|
|---|
| 158 | $sStatusText = '_Save profile successful';
|
|---|
| 159 |
|
|---|
| 160 | reparseObjTags( 'profile', $this->iProfileID );
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | if( $this -> bAjaxMode ) {
|
|---|
| 165 | //print_r( $_POST );
|
|---|
| 166 | $this -> showErrorsJson();
|
|---|
| 167 | exit;
|
|---|
| 168 | } else {
|
|---|
| 169 | ob_start();
|
|---|
| 170 | $this -> showEditForm( $sStatusText );
|
|---|
| 171 | return ob_get_clean();
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | function showErrorsJson() {
|
|---|
| 176 | header('Content-Type:text/javascript');
|
|---|
| 177 |
|
|---|
| 178 | echo $this -> oPF -> genJsonErrors( $this -> aErrors, $this -> bCouple );
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | function showEditForm( $sStatusText ) {
|
|---|
| 182 | //echoDbg( $this -> aValues );exit;
|
|---|
| 183 |
|
|---|
| 184 | $aFormAttrs = array(
|
|---|
| 185 | 'id' => 'edit_form',
|
|---|
| 186 | 'onsubmit' => 'return validateEditForm(this);',
|
|---|
| 187 | 'action' => ( $_SERVER['PHP_SELF'] . '?ID=' . $this -> iProfileID )
|
|---|
| 188 | );
|
|---|
| 189 |
|
|---|
| 190 | $aTableAttrs = array(
|
|---|
| 191 | 'id' => 'edit_form_table'
|
|---|
| 192 | );
|
|---|
| 193 |
|
|---|
| 194 | $aFormParams = array(
|
|---|
| 195 | 'hidden' => array( 'ID' => $this -> iProfileID, 'do_submit' => '1' )
|
|---|
| 196 | );
|
|---|
| 197 |
|
|---|
| 198 | $aTableParams = array(
|
|---|
| 199 | 'double' => $this -> bCouple,
|
|---|
| 200 | 'second_enabled' => $this -> bCouple
|
|---|
| 201 | );
|
|---|
| 202 |
|
|---|
| 203 | $aTableParams['headers'] = array( '', _t( '_First Person' ), _t( '_Second Person' ) );
|
|---|
| 204 | $aTableParams['headers_add'] = 'class="header form_second_col"' . ( $this -> bCouple ? '' : ' style="display: none;"' );
|
|---|
| 205 |
|
|---|
| 206 | $aButtons = array(
|
|---|
| 207 | array(
|
|---|
| 208 | 'type' => 'submit',
|
|---|
| 209 | 'value' => _t( '_Save' ),
|
|---|
| 210 | 'class' => 'input_submit'
|
|---|
| 211 | )
|
|---|
| 212 | );
|
|---|
| 213 |
|
|---|
| 214 | /* @var $oForm BxTemplFormView */
|
|---|
| 215 | $oForm = new BxTemplFormView( 'edit_form' );
|
|---|
| 216 | $oForm -> begin( $aFormAttrs, $aTableAttrs, $aFormParams, $aTableParams );
|
|---|
| 217 |
|
|---|
| 218 | foreach( $this -> aBlocks as $aBlock ) {
|
|---|
| 219 | $oForm -> beginBlock( _t( $aBlock['Caption'] ) );
|
|---|
| 220 |
|
|---|
| 221 | foreach( $aBlock['Items'] as $aItem ) {
|
|---|
| 222 |
|
|---|
| 223 | $aCol0 = array();
|
|---|
| 224 |
|
|---|
| 225 | $aCol0['Type'] = $aItem['Type'];
|
|---|
| 226 | $aCol0['Name'] = ( $aItem['Type'] == 'system' ) ? $aItem['Name'] : ( $aItem['Name'] . '[0]' );
|
|---|
| 227 | $aCol0['Mandatory'] = $aItem['Type'] == 'pass' ? false : $aItem['Mandatory'];
|
|---|
| 228 | $aCol0['Control'] = $aItem['Control'];
|
|---|
| 229 | $aCol0['Values'] = $aItem['Values'];
|
|---|
| 230 | $aCol0['UseLKey'] = $aItem['UseLKey'];
|
|---|
| 231 |
|
|---|
| 232 | $aCol0['Caption'] = _t( $aItem['Caption'] );
|
|---|
| 233 | $aCol0['Desc'] = _t( $aItem['Desc'] );
|
|---|
| 234 | if( $aCol0['Desc'] == $aItem['Desc'] )
|
|---|
| 235 | $aCol0['Desc'] = '';
|
|---|
| 236 |
|
|---|
| 237 | // set value
|
|---|
| 238 | if( isset( $this -> aValues[0][ $aItem['Name'] ] ) )
|
|---|
| 239 | $aCol0['Value'] = $this -> aValues[0][ $aItem['Name'] ];
|
|---|
| 240 | elseif( $aItem['Name'] == 'Couple' )
|
|---|
| 241 | $aCol0['Value'] = $this -> bCouple;
|
|---|
| 242 | elseif( $aItem['Name'] == 'Membership' )
|
|---|
| 243 | $aCol0['Value'] = getMemberMembershipInfo($this -> iProfileID);
|
|---|
| 244 |
|
|---|
| 245 | // set error
|
|---|
| 246 | if( isset( $this -> aErrors[0][ $aItem['Name'] ] ) )
|
|---|
| 247 | $aCol0['Error'] = $this -> aErrors[0][ $aItem['Name'] ];
|
|---|
| 248 |
|
|---|
| 249 | // check second person's field
|
|---|
| 250 | if( $this -> bCouple and !in_array( $aItem['Name'], $this -> aCoupleMutualFields ) ) {
|
|---|
| 251 | $aCol1 = array();
|
|---|
| 252 |
|
|---|
| 253 | $aCol1['Type'] = $aItem['Type'];
|
|---|
| 254 | $aCol1['Name'] = $aItem['Name'] . '[1]';
|
|---|
| 255 | $aCol1['Control'] = $aItem['Control'];
|
|---|
| 256 | $aCol1['Values'] = $aItem['Values'];
|
|---|
| 257 | $aCol1['UseLKey'] = $aItem['UseLKey'];
|
|---|
| 258 |
|
|---|
| 259 | // set value
|
|---|
| 260 | if( isset( $this -> aValues[1][ $aItem['Name'] ] ) )
|
|---|
| 261 | $aCol1['Value'] = $this -> aValues[1][ $aItem['Name'] ];
|
|---|
| 262 |
|
|---|
| 263 | // set error
|
|---|
| 264 | if( isset( $this -> aErrors[1][ $aItem['Name'] ] ) )
|
|---|
| 265 | $aCol1['Error'] = $this -> aValues[1][ $aItem['Name'] ];
|
|---|
| 266 |
|
|---|
| 267 | //echoDbg( $aCol0 );
|
|---|
| 268 | $oForm -> addRow( $aCol0, $aCol1 );
|
|---|
| 269 | } else
|
|---|
| 270 | $oForm -> addRow( $aCol0 );
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | $oForm -> endBlock();
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | $oForm -> end( $aButtons );
|
|---|
| 277 |
|
|---|
| 278 | if( $sStatusText )
|
|---|
| 279 | echo '<div class="notice_text">' . _t($sStatusText) . "</div>";
|
|---|
| 280 |
|
|---|
| 281 | echo $oForm -> getCode();
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | function saveProfile() {
|
|---|
| 285 | $aDiff = $this -> getDiffValues(0);
|
|---|
| 286 | $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
|
|---|
| 287 |
|
|---|
| 288 | $aUpd['DateLastEdit'] = date( 'Y-m-d H:i:s' );
|
|---|
| 289 | if( !getParam('autoApproval_ifProfile') && $this -> iArea == 2 )
|
|---|
| 290 | $aUpd['Status'] = 'Approval';
|
|---|
| 291 |
|
|---|
| 292 | if( ( $this -> iArea == 3 or $this -> iArea == 4 ) and isset( $_POST['doSetMembership'] ) and $_POST['doSetMembership'] == 'yes' )
|
|---|
| 293 | $this -> setMembership();
|
|---|
| 294 |
|
|---|
| 295 | $this -> oPC -> updateProfile( $this -> iProfileID, $aUpd );
|
|---|
| 296 |
|
|---|
| 297 | clearProfileMatchCache( $this -> iProfileID );
|
|---|
| 298 |
|
|---|
| 299 | if( $this -> bCouple ) {
|
|---|
| 300 | $aDiff = $this -> getDiffValues(1);
|
|---|
| 301 | $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
|
|---|
| 302 |
|
|---|
| 303 | $aUpd['DateLastEdit'] = date( 'Y-m-d H:i:s' );
|
|---|
| 304 | if( !getParam('autoApproval_ifProfile') && $this -> iArea == 2 )
|
|---|
| 305 | $aUpd['Status'] = 'Approval';
|
|---|
| 306 |
|
|---|
| 307 | $this -> oPC -> updateProfile( $this -> aProfiles[0]['Couple'], $aUpd );
|
|---|
| 308 |
|
|---|
| 309 | clearProfileMatchCache( $this -> aProfiles[0]['Couple'] );
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | function setMembership() {
|
|---|
| 315 |
|
|---|
| 316 | $iMshipID = (int)$_POST['MembershipID'];
|
|---|
| 317 | $iMshipDays = (int)$_POST['MembershipDays']; // 0 = unlim
|
|---|
| 318 | $bStartsNow = ($_POST['MembershipImmediately'] == 'on');
|
|---|
| 319 |
|
|---|
| 320 | $bResult = setMembership( $this -> iProfileID, $iMshipID, $iMshipDays, $bStartsNow );
|
|---|
| 321 |
|
|---|
| 322 | if( $bResult ) {
|
|---|
| 323 | $check_res = checkAction($this -> iProfileID, ACTION_ID_USE_CHAT);
|
|---|
| 324 | if ($check_res[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
|
|---|
| 325 | modules_unblock($this -> iProfileID, 'chat');
|
|---|
| 326 | else
|
|---|
| 327 | modules_block($this -> iProfileID, 'chat');
|
|---|
| 328 |
|
|---|
| 329 | $check_res = checkAction($this -> iProfileID, ACTION_ID_USE_FORUM);
|
|---|
| 330 | if ($check_res[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
|
|---|
| 331 | modules_unblock($this -> iProfileID, 'forum');
|
|---|
| 332 | else
|
|---|
| 333 | modules_block($this -> iProfileID, 'forum');
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | return $bResult;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | function getDiffValues($iInd) {
|
|---|
| 340 | $aOld = $this -> aOldValues[$iInd];
|
|---|
| 341 | $aNew = $this -> aValues[$iInd];
|
|---|
| 342 |
|
|---|
| 343 | $aDiff = array();
|
|---|
| 344 | foreach( $aNew as $sName => $mNew ){
|
|---|
| 345 | $mOld = $aOld[$sName];
|
|---|
| 346 |
|
|---|
| 347 | if( is_array($mNew) ) {
|
|---|
| 348 | if( count($mNew) == count($mOld) ) {
|
|---|
| 349 | //compare each value
|
|---|
| 350 | $mOldS = $mOld;
|
|---|
| 351 | $mNewS = $mNew;
|
|---|
| 352 | sort( $mOldS ); //sort them for correct comparison
|
|---|
| 353 | sort( $mNewS );
|
|---|
| 354 |
|
|---|
| 355 | foreach( $mNewS as $iKey => $sVal )
|
|---|
| 356 | if( $mNewS[$iKey] != $mOld[$iKey] ) {
|
|---|
| 357 | $aDiff[$sName] = $mNew; //found difference
|
|---|
| 358 | break;
|
|---|
| 359 | }
|
|---|
| 360 | } else
|
|---|
| 361 | $aDiff[$sName] = $mNew;
|
|---|
| 362 | } else {
|
|---|
| 363 | if( $mNew != $mOld )
|
|---|
| 364 | $aDiff[$sName] = $mNew;
|
|---|
| 365 | }
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | return $aDiff;
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | } |
|---|