Commit 8a1a242e authored by Penny Leach's avatar Penny Leach
Browse files

activity and account prefs forms

parent 9b6d2a9f
......@@ -37,8 +37,11 @@ $notifications = plugins_installed('notification');
$elements = array();
foreach ($activitytypes as $type) {
if (!$dv = $SESSION->get_activity_preference($type->name)) {
$dv = 'internal';
}
$elements[$type->name] = array(
'value' => $type->name,
'defaultvalue' => $dv,
'type' => 'select',
'title' => get_string('type' . $type->name, 'activity'),
'options' => array(),
......@@ -76,24 +79,11 @@ function activityprefs_submit($values) {
global $activitytypes, $SESSION;
$userid = $SESSION->get('id');
db_begin();
delete_records('usr_activity_preference', 'usr', $userid);
try {
foreach ($activitytypes as $type) {
$t = new StdClass;
$t->usr = $userid;
$t->type = $type->name;
$t->method = $values[$type->name];
insert_record('usr_activity_preference', $t);
}
}
catch (Exception $e) {
db_rollback();
throw $e;
// @todo actually return a json failure
foreach ($activitytypes as $type) {
$SESSION->set_activity_preference($type->name, $values[$type->name]);
}
db_commit();
echo json_encode(array('error' => false, 'message' => get_string('prefssaved', 'account')));
exit;
}
......
......@@ -43,7 +43,7 @@ $prefsform = array(
'elements' => array(
'friendscontrol' => array(
'type' => 'radio',
'value' => $prefs->friendscontrol,
'defaultvalue' => $prefs->friendscontrol,
'title' => get_string('friendsdescr', 'account'),
'separator' => HTML_BR,
'options' => array(
......@@ -57,7 +57,7 @@ $prefsform = array(
),
'wysiwyg' => array(
'type' => 'radio',
'value' => $prefs->wysiwyg,
'defaultvalue' => $prefs->wysiwyg,
'title' => get_string('wysiwygdescr', 'account'),
'options' => array(
1 => get_string('on', 'account'),
......@@ -69,7 +69,7 @@ $prefsform = array(
),
'messages' => array(
'type' => 'radio',
'value' => $prefs->messages,
'defaultvalue' => $prefs->messages,
'title' => get_string('messagesdescr', 'account'),
'separator' => HTML_BR,
'options' => array(
......@@ -81,6 +81,15 @@ $prefsform = array(
'required' => true
)
),
'lang' => array(
'type' => 'select',
'defaultvalue' => $prefs->lang,
'title' => get_string('language', 'account'),
'options' => get_languages(),
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('save'),
......@@ -94,16 +103,15 @@ $smarty->assign('form', form($prefsform));
$smarty->display('account/index.tpl');
function accountprefs_submit($values) {
global $SESSION;
log_debug($values);
// use this as looping through values is not safe.
$expectedprefs = expected_account_preferences();
try {
foreach (array_keys($expectedprefs) as $pref) {
set_account_preference($SESSION->get('id'), $pref, $expectedprefs[$pref]);
}
}
catch (Exception $e) {
foreach (array_keys($expectedprefs) as $pref) {
$SESSION->set_account_preference($pref, $values[$pref]);
}
echo json_encode(array('error' => false, 'message' => get_string('prefssaved', 'account')));
exit;
}
......
......@@ -40,5 +40,9 @@ $string['messagesnobody'] = 'Allow no-one to message me';
$string['messagesfriends'] = 'Allow people on my friends list to message me';
$string['messagesallow'] = 'Allow anyone to message me';
$string['language'] = 'Language';
$string['prefssaved'] = 'Preferences saved';
$string['prefsnotsaved'] = 'Failed to save your preferences!';
?>
......@@ -37,9 +37,9 @@ function load_activity_preferences($userid) {
if (empty($userid)) {
throw new InvalidArgumentException("couldn't load activity preferences, no user id specified");
}
if ($prefs = get_records('usr_activity_preference', 'usr', $userid)) {
if ($prefs = get_rows('usr_activity_preference', 'usr', $userid)) {
foreach ($prefs as $p) {
$prefs[$p->activity] = $p->method;
$prefs[$p['activity']] = $p['method'];
}
}
return $prefs;
......@@ -60,9 +60,9 @@ function load_account_preferences($userid) {
if (empty($userid)) {
throw new InvalidArgumentException("couldn't load account preferences, no user id specified");
}
if ($prefs = get_records('usr_account_preference', 'usr', $userid)) {
if ($prefs = get_rows('usr_account_preference', 'usr', $userid)) {
foreach ($prefs as $p) {
$prefs[$p->field] = $p->value;
$prefs[$p['field']] = $p['value'];
}
}
foreach ($expectedprefs as $field => $default) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment