/** * Save a profile field. * Exception is 'socialprofile' field. It is made up of 2 fields: * socialprofile_profileurl, * socialprofile_profiletype * @param int $userid * @param string $field * @param string (or array for socialprofile) $value * @param int $new - Whether the user is new (avoid unnecessary queries) */ function set_profile_field($userid, $field, $value, $new = FALSE) { safe_require('artefact', 'internal'); // this is a special case that replaces the primary email address with the // specified one if ($field == 'email') { if (!$new) { try { $email = artefact_instance_from_type('email', $userid); } catch (ArtefactNotFoundException $e) { // We'll create a new artefact then. } } if (!isset($email)) { $email = new ArtefactTypeEmail(0, null, TRUE); $email->set('owner', $userid); } $email->set('title', $value); $email->commit(); } else { if ($field == 'socialprofile') { if (in_array($value['socialprofile_profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) { $desc = get_string($value['socialprofile_profiletype'], 'artefact.internal'); $type = $value['socialprofile_profiletype']; } else { $desc = $value['socialprofile_profiletype']; $type = 'website'; } $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid), $new); $profile->set('title', $value['socialprofile_profileurl']); $profile->set('description', $desc); $profile->set('note', $type); $profile->commit(); } else { $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid), $new); $profile->set('title', $value); $profile->commit(); } } }
function set_profile_field($userid, $field, $value) { safe_require('artefact', 'internal'); // this is a special case that replaces the primary email address with the // specified one if ($field == 'email') { try { $email = artefact_instance_from_type('email', $userid); } catch (ArtefactNotFoundException $e) { $email = new ArtefactTypeEmail(); $email->set('owner', $userid); } $email->set('title', $value); $email->commit(); } else { $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid)); $profile->set('title', $value); $profile->commit(); } }
$key = param_variable('key'); $decline = param_boolean('decline'); $row = get_record('artefact_internal_profile_email', 'email', $email, 'key', $key, null, null, 'owner,artefact,email,verified,' . db_format_tsfield('expiry')); if ($row) { if ($decline) { delete_records_select('artefact_internal_profile_email', 'verified=0 AND key=? AND email=?', array($key, $email)); $SESSION->add_ok_msg(get_string('emailactivationdeclined', 'artefact.internal')); redirect(get_config('wwwroot')); } if ($row->expiry > time()) { if ($row->artefact) { $artefact = new ArtefactTypeEmail($row->artefact); } else { $artefact = new ArtefactTypeEmail(); } $artefact->set('owner', $row->owner); $artefact->set('title', $row->email); $artefact->commit(); update_record('artefact_internal_profile_email', (object) array('verified' => 1, 'key' => null, 'expiry' => null, 'artefact' => $artefact->get('id')), (object) array('owner' => $row->owner, 'email' => $row->email)); $SESSION->add_ok_msg(get_string('emailactivationsucceeded', 'artefact.internal')); // Update user's email if this email address is primary (principal == 1) if (record_exists('artefact_internal_profile_email', 'owner', $row->owner, 'email', $row->email, 'principal', 1)) { update_record('usr', (object) array('email' => $row->email), (object) array('id' => $row->owner)); redirect(get_config('wwwroot')); } else { redirect(get_config('wwwroot') . 'artefact/internal/index.php?fs=contact'); } } else { $message = get_string('verificationlinkexpired', 'artefact.internal'); } } else {