8 require_once(
'./inc/header.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC .
'admin.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC .
'db.inc.php' );
11 require_once( CH_DIRECTORY_PATH_INC .
'match.inc.php' );
47 $this -> aProfiles = array( 0 => array(), 1 => array() );
48 $this -> aValues = array( 0 => array(), 1 => array() );
49 $this -> aErrors = array( 0 => array(), 1 => array() );
52 $this -> iProfileID = (int)
$iId;
57 if( !$this -> iProfileID ) {
71 $this -> bAjaxMode = ( isset( $_SERVER[
'HTTP_X_REQUESTED_WITH'] )
and $_SERVER[
'HTTP_X_REQUESTED_WITH'] ==
'XMLHttpRequest' );
72 $this -> bForceAjaxSave =
ch_get(
'force_ajax_save');
74 parent::__construct(
'pedit');
79 if( !$this -> iProfileID )
80 return _t(
'_Profile not specified' );
83 return _t(
'_You cannot edit this profile' );
89 $this -> aProfiles[0] = $this -> oPC ->
getProfileInfo( $this -> iProfileID );
90 if( !$this -> aProfiles[0] )
91 return _t(
'_Profile not found' );
93 if( $this -> aProfiles[0][
'Couple'] ) {
94 $this -> aProfiles[1] = $this -> oPC ->
getProfileInfo( $this -> aProfiles[0][
'Couple'] );
96 if( !$this -> aProfiles[1] )
97 return _t(
'_Couple profile not found' );
99 $this -> bCouple =
true;
104 if( !$this -> oPF -> aArea )
105 return 'Profile Fields cache not loaded. Cannot continue.';
107 $this -> aCoupleMutualFields = $this -> oPF -> getCoupleMutualFields();
110 $this -> aBlocks = $this -> oPF -> aArea;
113 $this -> aItems = array();
114 foreach ($this -> aBlocks
as $aBlock) {
115 foreach( $aBlock[
'Items']
as $iItemID => $aItem )
116 $this -> aItems[$iItemID] = $aItem;
119 $this -> aValues[0] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[0] );
120 if( $this -> bCouple )
121 $this -> aValues[1] = $this -> oPF -> getValuesFromProfile( $this -> aProfiles[1] );
123 $this -> aOldValues = $this -> aValues;
126 if( isset($_POST[
'do_submit']) ) {
127 $this -> oPF -> processPostValues( $this -> bCouple, $this -> aValues, $this -> aErrors, 0, $this -> iProfileID, (
int)$_POST[
'pf_block'] );
130 $aMutualFieldsCopy = $this->oPF->getCoupleMutualFieldsCopy();
131 if(!
empty($aMutualFieldsCopy) && is_array($aMutualFieldsCopy)) {
132 $aMutualFieldsCopy = array_intersect_key($this -> aValues[0], array_flip($aMutualFieldsCopy));
134 $this -> aValues[1] = array_merge($this -> aValues[1], $aMutualFieldsCopy);
137 if(
empty( $this -> aErrors[0] )
and empty( $this -> aErrors[1] ) ) {
138 if (!$this -> bAjaxMode
or $this->bForceAjaxSave) {
145 if($this -> bAjaxMode) {
153 $oPrivacy =
new ChWsbPrivacy(
'sys_page_compose_privacy',
'id',
'user_id');
155 $this->aFormPrivacy = array(
156 'form_attrs' => array(
157 'id' =>
'profile_edit_privacy',
158 'name' =>
'profile_edit_privacy',
159 'action' => CH_WSB_URL_ROOT .
'pedit.php?ID=' . $this->iProfileID,
161 'enctype' =>
'multipart/form-data'
169 'submit_name' =>
'save_privacy'
173 'profile_id' => array(
175 'name' =>
'profile_id',
176 'value' => $this->iProfileID,
178 'allow_view_to' => $oPrivacy->getGroupChooser(
getLoggedId(),
'profile',
'view'),
179 'save_privacy' => array(
181 'name' =>
'save_privacy',
182 'value' =>
_t(
'_edit_profile_privacy_save'),
187 $this->aFormPrivacy[
'inputs'][
'allow_view_to'][
'value'] =
$aProfileInfo[
'allow_view_to'];
192 if(
$oForm->isSubmittedAndValid()) {
194 $iAllowViewTo = (int)$_POST[
'allow_view_to'];
197 if ((
int)
db_res(
"UPDATE `Profiles` SET `allow_view_to`='" . $iAllowViewTo .
"' WHERE `ID`='" .
$iProfileId .
"' LIMIT 1") > 0) {
223 $this->aFormMembership = array(
224 'form_attrs' => array(
225 'id' =>
'profile_edit_membership',
226 'name' =>
'profile_edit_membership',
227 'action' => CH_WSB_URL_ROOT .
'pedit.php?ID=' . $this->iProfileID,
229 'enctype' =>
'multipart/form-data'
237 'submit_name' =>
'save_membership'
241 'doSetMembership' => array(
243 'name' =>
'doSetMembership',
246 'MembershipInfo' => array(
248 'caption' =>
_t(
'_Membership_current'),
251 'MembershipID' => array(
253 'name' =>
'MembershipID',
254 'caption' =>
_t(
'_Membership_name'),
259 'onchange' =>
'checkStandard()'
264 'error' =>
_t(
'_Membership_name_err_empty'),
270 'MembershipDays' => array(
272 'name' =>
'MembershipDays',
273 'caption' =>
_t(
'_Membership_days'),
274 'value' => $sUnlimited,
277 'onfocus' =>
"if(MembershipDays.value == '" . $sUnlimited .
"') MembershipDays.value = ''",
278 'onblur' =>
"if(MembershipDays.value == '') MembershipDays.value = '" . $sUnlimited .
"'"
280 'info' =>
_t(
'_Membership_days_info'),
285 'MembershipImmediately' => array(
286 'type' =>
'checkbox',
287 'name' =>
'MembershipImmediately',
288 'caption' =>
_t(
'_Membership_starts'),
295 'save_membership' => array(
297 'name' =>
'save_membership',
298 'value' =>
_t(
'_Membership_save'),
306 $this->aFormMembership[
'inputs'][
'MembershipID'][
'values'][] = array(
'key' =>
$iId,
'value' =>
$sName);
312 if(
$oForm->isSubmittedAndValid()) {
313 $iMshipID = (int)
$oForm->getCleanValue(
'MembershipID');
314 $iMshipDays = (int)
$oForm->getCleanValue(
'MembershipDays');
315 $bStartsNow =
$oForm->getCleanValue(
'MembershipImmediately') ==
'on';
317 $bSave =
setMembership( $this -> iProfileID, $iMshipID, $iMshipDays, $bStartsNow );
318 $sContent .=
MsgBox(
_t($bSave ?
'_Membership_save_msg_saved' :
'_Membership_save_err_saved'), 3);
325 $sMembershipCurrent = $aMembershipCurrent[
'Name'];
327 $sMembershipCurrent .=
', ' . (!isset($aMembershipCurrent[
'DateExpires']) ?
_t(
'_MEMBERSHIP_EXPIRES_NEVER') :
_t(
'_MEMBERSHIP_EXPIRES',
defineTimeInterval($aMembershipCurrent[
'DateExpires'])));
329 $oForm->aInputs[
'MembershipInfo'][
'content'] = $sMembershipCurrent;
333 <script
type=
"text/javascript">
335 function checkStandard()
337 var iId = parseInt($(
"[name='MembershipID']").val());
339 $(
"[name='MembershipDays']").attr(
'disabled',
'disabled');
340 $(
"[name='MembershipImmediately']").attr(
'disabled',
'disabled');
342 $(
"[name='MembershipDays']").removeAttr(
'disabled');
343 $(
"[name='MembershipImmediately']").removeAttr(
'disabled');
358 header(
'Content-Type:text/javascript; charset=utf-8');
359 echo $this -> oPF -> genJsonErrors( $this -> aErrors, $this -> bCouple );
364 $aEditFormParams = array(
365 'couple_enabled' => $this->bCouple,
366 'couple' => $this->bCouple,
367 'page' => $this->iPage,
368 'hiddens' => array(
'ID' => $this -> iProfileID,
'do_submit' =>
'1'),
369 'errors' => $this->aErrors,
370 'values' => $this->aValues,
371 'profile_id' => $this->iProfileID,
377 return $sStatusText . $this->oPF->getFormCode($aEditFormParams);
384 $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
386 $aUpd[
'DateLastEdit'] = date(
'Y-m-d H:i:s' );
387 if( !
getParam(
'autoApproval_ifProfile') && $this -> iArea == 2 )
388 $aUpd[
'Status'] =
'Approval';
390 if( ( $this -> iArea == 3
or $this -> iArea == 4 )
and isset( $_POST[
'doSetMembership'] )
and $_POST[
'doSetMembership'] ==
'yes' )
393 $bResult = $this -> oPC -> updateProfile( $this -> iProfileID, $aUpd );
395 ch_login($this -> iProfileID,
false,
false);
398 ChWsbService::call(
'wmap',
'response_entry_change', array(
'profiles', $this->iProfileID));
405 if( $this -> bCouple ) {
407 $aUpd = $this -> oPF -> getProfileFromValues( $aDiff );
409 $aUpd[
'DateLastEdit'] = date(
'Y-m-d H:i:s' );
410 if( !
getParam(
'autoApproval_ifProfile') && $this -> iArea == 2 )
411 $aUpd[
'Status'] =
'Approval';
413 $this -> oPC -> updateProfile( $this -> aProfiles[0][
'Couple'], $aUpd );
419 $aOld = $this -> aOldValues[$iInd];
420 $aNew = $this -> aValues[$iInd];
423 foreach( $aNew
as $sName => $mNew ){
426 if( is_array($mNew) ) {
427 if( count($mNew) == count($mOld) ) {
434 foreach( $mNewS
as $iKey => $sVal )
435 if( $mNewS[$iKey] != $mOld[$iKey] ) {
453 $_page[
'extra_js'] .=
'<script type="text/javascript" language="JavaScript" src="' .
$site[
'plugins'] .
'jquery/jquery.form.min.js"></script>';
454 $_page[
'extra_js'] .=
'<script type="text/javascript" language="JavaScript" src="inc/js/pedit.js"></script>';
459 $GLOBALS[
'oSysTemplate']->displayAccessDenied ();