buildCommonNS();
$out['messages'] = array();
$users = DB_DataObject::factory('Users');
if ($users->get('username', $out['page_username']) != 1 ) { // TODO: This should be a 404 error?
header("Location: ${out['BASE_URL']}");
} elseif ($users->username != $out['auth_username']) { // TODO: This should be a 403 error?
header("Location: ${out['BASE_URL']}");
} else {
// Start building the settings form.
$form = new HTML_QuickForm('settings_form', 'POST', $out['userpath']."/settings");
// Convert the user record into form defaults
$defaults = $users->toArray();
unset($defaults['password']);
$form->setDefaults($defaults);
// Set up settings form.
$form->addElement('static', 'change_passwd_hdr', '
Change Password
');
$form->addElement('password', 'password', 'Password', array('maxlength'=>255));
$form->addElement('password', 'password_verify', 'Password (verify)', array('maxlength'=>255));
$form->addElement('static', 'change_profile_hdr', 'Change Profile Info
');
$form->addElement('text', 'full_name', 'Full Name');
$form->addElement('text', 'email', 'Email');
$form->addElement('text', 'url', 'Home URL');
$form->addElement('text', 'location', 'Location');
$form->addElement('textarea', 'description', 'Bio / Description');
$form->addElement('file', 'profile_image', 'Profile Image');
$form->addElement('static', 'profile_image_img',
'
');
$form->addElement('submit', 'save', 'Save changes');
// Enforce matching passwords.
$form->addRule(array('password', 'password_verify'), 'Passwords do not match', 'compare', 'eq');
/**
* Attempt to validate the form data incoming.
*/
if ($form->validate()) {
// Update the user's profile
$original = $users->clone();
$values = $form->getSubmitValues();
foreach (array('email','full_name','location','description','url') as $name) {
$users->$name = $values[$name];
}
$users->update($original);
array_push($out['messages'], "Profile changes saved.");
// Change the user's password.
if ($values['password']) {
array_push($out['messages'], "Password changed.");
}
// Replace the user's avatar image.
$profile_image = $form->getElement('profile_image')->getValue();
if ($profile_image && $profile_image['tmp_name']) {
$this->updateAvatarImage($out['auth_username'], $profile_image['tmp_name']);
array_push($out['messages'], "Avatar image changed.");
}
} else {
}
// Extract the results of form validation in an array for the template.
$renderer = new HTML_QuickForm_Renderer_Array();
$form->accept($renderer);
$out['form'] = $renderer->toArray();
// Render the signup template.
echo $this->renderTemplate('settings', $out);
}
?>