Would a button do?
To do this you have to create a custom module, or add to an existing custom module.
First define your form. All you need is a submit button, and the value can be any label you want on the button.
function modulename_onlinevisibility_form( $form, &$form_state) {
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Change my on-line visibility'),
)
}
Then you need a submit handler for the form:
function modulename_onlinevisibility_form_submit(&$form_state) {
global $user;
$account = user_load($user->uid);
$account->field_optout[LANGUAGE_NONE][0]['value'] =
(isset($account->field_optout[LANGUAGE_NONE][0]['value'])
&& ($account->field_optout[LANGUAGE_NONE][0]['value'] == 1))
? 0 : 1;
user_save($account);
}
This will switch the value of the boolean field turning it off if on and visa versa, for the logged in user. (Profile fields may not be included in the $user variable, so a full user object is loaded using user_load.)
Then in your view, add a footer using the Global: PHP type, and add the code:
<?php
print render(drupal_get_form('modulename_onlinevisibility_form'));
?>
This will place a button at the bottom of your view which will toggle the user's on-line visibility.
EDIT.
If you are using the Profile2 module, then the code for the submit handler should be changed to:
function modulename_onlinevisibility_form_submit(&$form_state) {
global $user;
$profile_type = 'main'; // substitute the machine name of the profile if you are not using the default
$profile = profile2_load_by_user( $user, $profile_type);
$profile->field_optout[LANGUAGE_NONE][0]['value'] =
(isset($profile->field_optout[LANGUAGE_NONE][0]['value'])
&& ($profile->field_optout[LANGUAGE_NONE][0]['value'] == 1))
? 0 : 1;
profile2_save($profile);
}
Profile2 profiles are not loaded by user_load.