Commit c914bccb authored by Eugene Venter's avatar Eugene Venter

Add general account settings when adding user(s)

Bug #806777

General account options/settings added to functionality for manually adding a
single user, as well as adding users via CSV.

These are exactly the same settings as found in the 'General account options'
section on the Settings page.

Change-Id: I4fa5b50a588abc4747098f6dce186f600f73097f
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent a185ceed
......@@ -88,99 +88,10 @@ if ($authobj->authname == 'internal') {
$elements['accountoptionsdesc'] = array(
'value' => '<tr><td colspan="2"><h3>' . get_string('accountoptionsdesc', 'account') . '</h3></td></tr>'
);
$elements['friendscontrol'] = array(
'type' => 'radio',
'defaultvalue' => $prefs->friendscontrol,
'title' => get_string('friendsdescr', 'account'),
'separator' => '<br>',
'options' => array(
'nobody' => get_string('friendsnobody', 'account'),
'auth' => get_string('friendsauth', 'account'),
'auto' => get_string('friendsauto', 'account')
),
'help' => true
);
$elements['wysiwyg'] = array(
'type' => 'checkbox',
'defaultvalue' => (get_config('wysiwyg')) ? get_config('wysiwyg') == 'enable' : $prefs->wysiwyg,
'title' => get_string('wysiwygdescr', 'account'),
'help' => true,
'disabled' => get_config('wysiwyg'),
);
$elements['maildisabled'] = array(
'type' => 'checkbox',
'defaultvalue' => get_account_preference($USER->get('id'), 'maildisabled'),
'title' => get_string('email'),
'help' => true,
);
$elements['messages'] = array(
'type' => 'radio',
'defaultvalue' => $prefs->messages,
'title' => get_string('messagesdescr', 'account'),
'separator' => '<br>',
'options' => array(
'nobody' => get_string('messagesnobody', 'account'),
'friends' => get_string('messagesfriends', 'account'),
'allow' => get_string('messagesallow', 'account'),
),
'help' => true,
);
$languages = get_languages();
$elements['lang'] = array(
'type' => 'select',
'defaultvalue' => $prefs->lang,
'title' => get_string('language', 'account'),
'options' => array_merge(array('default' => get_string('sitedefault', 'admin') . ' (' . $languages[get_config('lang')] . ')'), $languages),
'help' => true,
'ignore' => count($languages) < 2,
);
$elements['addremovecolumns'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->addremovecolumns,
'title' => get_string('showviewcolumns', 'account'),
'help' => 'true'
);
// TODO: add a way for plugins (like blog!) to have account preferences
$elements['multipleblogs'] = array(
'type' => 'checkbox',
'title'=> get_string('enablemultipleblogs' ,'account'),
'description' => get_string('enablemultipleblogsdescription', 'account'),
'defaultvalue' => $prefs->multipleblogs,
);
if (get_config('showtagssideblock')) {
$elements['tagssideblockmaxtags'] = array(
'type' => 'text',
'size' => 4,
'title' => get_string('tagssideblockmaxtags', 'account'),
'description' => get_string('tagssideblockmaxtagsdescription', 'account'),
'defaultvalue' => isset($prefs->tagssideblockmaxtags) ? $prefs->tagssideblockmaxtags : get_config('tagssideblockmaxtags'),
'rules' => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 1000),
);
}
if (get_config('userscanhiderealnames')) {
$elements['hiderealname'] = array(
'type' => 'checkbox',
'title' => get_string('hiderealname', 'account'),
'description' => get_string('hiderealnamedescription', 'account'),
'defaultvalue' => $prefs->hiderealname,
);
}
if (get_config('homepageinfo')) {
$elements['showhomeinfo'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->showhomeinfo,
'title' => get_string('showhomeinfo', 'account'),
'help' => 'true'
);
}
if (get_config('allowmobileuploads')) {
$elements['mobileuploadtoken'] = array(
'type' => 'text',
'title' => get_string('mobileuploadtoken', 'account'),
'description' => get_string('mobileuploadtokendescription', 'account'),
'defaultvalue' => isset($prefs->mobileuploadtoken) ? $prefs->mobileuploadtoken : get_config('mobileuploadtoken')
);
}
// Add general account options
$elements = array_merge($elements, general_account_prefs_form_elements($prefs));
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save')
......@@ -270,9 +181,10 @@ function accountprefs_submit(Pieform $form, $values) {
// Remember the user's language pref, so we can reload the page if they change it
$oldlang = $USER->get_account_preference('lang');
foreach (array_keys($expectedprefs) as $pref) {
if (isset($values[$pref])) {
$USER->set_account_preference($pref, $values[$pref]);
// Set user account preferences
foreach ($expectedprefs as $eprefkey => $epref) {
if (isset($values[$eprefkey]) && $values[$eprefkey] != get_account_preference($USER->get('id'), $eprefkey)) {
$USER->set_account_preference($eprefkey, $values[$eprefkey]);
}
}
......
......@@ -147,6 +147,12 @@ if (!($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutiona
);
}
// Add general account options
$prefs = (object) expected_account_preferences();
$elements = array_merge($elements, general_account_prefs_form_elements($prefs));
unset($prefs);
$form = pieform(array(
'name' => 'adduser',
'autofocus' => false,
......@@ -300,7 +306,7 @@ function adduser_submit(Pieform $form, $values) {
$values['remoteusername'] = null;
}
$user->id = create_user($user, array(), $authinstance->institution, $authinstance, $values['remoteusername']);
$user->id = create_user($user, array(), $authinstance->institution, $authinstance, $values['remoteusername'], $values);
if (isset($user->admin) && $user->admin) {
require_once('activity.php');
......
......@@ -110,8 +110,12 @@ if (count($authinstances) > 0) {
);
}
$prefs = (object) expected_account_preferences();
$form = array(
'name' => 'uploadcsv',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'authinstance' => $authinstanceelement,
'quota' => array(
......@@ -147,6 +151,13 @@ $form = array(
'description' => get_string('updateusersdescription', 'admin'),
'defaultvalue' => false,
),
'accountprefs' => array(
'type' => 'fieldset',
'legend' => get_string('accountoptionsdesc', 'account'),
'collapsible' => true,
'collapsed' => true,
'elements' => general_account_prefs_form_elements($prefs),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('uploadcsv', 'admin')
......@@ -154,6 +165,8 @@ $form = array(
)
);
unset($prefs);
if (!($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride'))) {
$form['elements']['quota'] = array(
'type' => 'text',
......@@ -503,13 +516,13 @@ function uploadcsv_submit(Pieform $form, $values) {
if (!$values['updateusers'] || !isset($UPDATES[$user->username])) {
$user->passwordchange = (int)$values['forcepasswordchange'];
$user->id = create_user($user, $profilefields, $institution, $authrecord, $remoteuser);
$user->id = create_user($user, $profilefields, $institution, $authrecord, $remoteuser, $values);
$addedusers[] = $user;
log_debug('added user ' . $user->username);
}
else if (isset($UPDATES[$user->username])) {
$updated = update_user($user, $profilefields, $remoteuser);
$updated = update_user($user, $profilefields, $remoteuser, $values);
if (empty($updated)) {
// Nothing changed for this user
......
<h3>Show controls to add and remove columns when editing a page</h3>
<p>You can choose to display a row with buttons <img src="/theme/raw/static/images/btn_addcolumn_left.png" alt="add"> <img src="/theme/raw/static/images/btn_removecolumn.png" alt="remove"> in the page editor. These buttons add and remove columns from that page.</p>
<p>You can choose to display a row with buttons <img src="../../theme/raw/static/images/btn_addcolumn_left.png" alt="add"> <img src="../../theme/raw/static/images/btn_removecolumn.png" alt="remove"> in the page editor. These buttons add and remove columns from that page.</p>
<p>Even if not enabled, you can change the number of columns for your page on the Page layout section.</p>
<h3>Show controls to add and remove columns when editing a page</h3>
<p>You can choose to display a row with buttons <img src="../../theme/raw/static/images/btn_addcolumn_left.png" alt="add"> <img src="../../theme/raw/static/images/btn_removecolumn.png" alt="remove"> in the page editor. These buttons add and remove columns from that page.</p>
<p>Even if not enabled, you can change the number of columns for your page on the Page layout section.</p>
<h3>Friends Control</h3>
<p>Choose whether other users may add you to their friends list. If you are added to a friends list, the owner of that list is added to your list. When you remove someone from your friends list you are also removed from their list. Choose either:</p>
<p><strong>Nobody may add me as a friend:</strong> no one may add you to their list.</p>
<p><strong>New friends require my authorisation:</strong> your authorisation is needed for you to be added to a list. If you approve, they will be added to your list.</p>
<p><strong>New friends are automatically authorised:</strong> anyone may add you to their list.</p>
<h3>Language</h3>
<p>You may be able customise the language in which your menu items and contextual help will appear. Contact your site administrator if you have any questions.</p>
<h3>Email</h3>
<p>Use this setting to stop Mahara from sending you email.</p>
<h3>Messages from other users</h3>
<p>Use this setting to choose who you wish to receive messages from.</p>
<p>Use the activity preferences area to decide how you will receive these messages.</p>
<p><strong>Note:</strong> These restrictions will not apply to site administrators or teaching staff.</p>
<h3>Passwords</h3>
<p>To change your login password, first enter your current password here, then enter your preferred new password in both the other boxes.</p>
<p>Your password must total at least six characters. It must contain at least one number, and at least two letters. Passwords are case sensitive, and must be different from your username.</p>
<h3>Show information about Mahara on the home page</h3>
<p>If "On", information about Mahara and what can be done with it will be displayed on the home page, above your dashboard.</p>
<h3>HTML Editor</h3>
<p>An HTML editor is available for use on some sections of the site. This is known as a ‘What you see is what you get’ (WYSIWYG) editor. This allows you to apply formatting to your text eg: bolded or italic text. If the editor is turned off you can only enter plain text.</p>
<p>This setting might be disabled by site admin.</p>
<p><strong>Note:</strong>HTML editors may appear and work slightly differently in some browsers.</p>
<h3>Show controls to add and remove columns when editing a page</h3>
<p>You can choose to display a row with buttons <img src="../../theme/raw/static/images/btn_addcolumn_left.png" alt="add"> <img src="../../theme/raw/static/images/btn_removecolumn.png" alt="remove"> in the page editor. These buttons add and remove columns from that page.</p>
<p>Even if not enabled, you can change the number of columns for your page on the Page layout section.</p>
<h3>Friends Control</h3>
<p>Choose whether other users may add you to their friends list. If you are added to a friends list, the owner of that list is added to your list. When you remove someone from your friends list you are also removed from their list. Choose either:</p>
<p><strong>Nobody may add me as a friend:</strong> no one may add you to their list.</p>
<p><strong>New friends require my authorisation:</strong> your authorisation is needed for you to be added to a list. If you approve, they will be added to your list.</p>
<p><strong>New friends are automatically authorised:</strong> anyone may add you to their list.</p>
<h3>Language</h3>
<p>You may be able customise the language in which your menu items and contextual help will appear. Contact your site administrator if you have any questions.</p>
<h3>Email</h3>
<p>Use this setting to stop Mahara from sending you email.</p>
<h3>Messages from other users</h3>
<p>Use this setting to choose who you wish to receive messages from.</p>
<p>Use the activity preferences area to decide how you will receive these messages.</p>
<p><strong>Note:</strong> These restrictions will not apply to site administrators or teaching staff.</p>
<h3>Passwords</h3>
<p>To change your login password, first enter your current password here, then enter your preferred new password in both the other boxes.</p>
<p>Your password must total at least six characters. It must contain at least one number, and at least two letters. Passwords are case sensitive, and must be different from your username.</p>
<h3>Show information about Mahara on the home page</h3>
<p>If "On", information about Mahara and what can be done with it will be displayed on the home page, above your dashboard.</p>
<h3>HTML Editor</h3>
<p>An HTML editor is available for use on some sections of the site. This is known as a ‘What you see is what you get’ (WYSIWYG) editor. This allows you to apply formatting to your text eg: bolded or italic text. If the editor is turned off you can only enter plain text.</p>
<p>This setting might be disabled by site admin.</p>
<p><strong>Note:</strong>HTML editors may appear and work slightly differently in some browsers.</p>
......@@ -212,6 +212,105 @@ function expected_account_preferences() {
);
}
function general_account_prefs_form_elements($prefs) {
$elements = array();
$elements['friendscontrol'] = array(
'type' => 'radio',
'defaultvalue' => $prefs->friendscontrol,
'title' => get_string('friendsdescr', 'account'),
'separator' => '<br>',
'options' => array(
'nobody' => get_string('friendsnobody', 'account'),
'auth' => get_string('friendsauth', 'account'),
'auto' => get_string('friendsauto', 'account')
),
'help' => true
);
$elements['wysiwyg'] = array(
'type' => 'checkbox',
'defaultvalue' => (get_config('wysiwyg')) ? get_config('wysiwyg') == 'enable' : $prefs->wysiwyg,
'title' => get_string('wysiwygdescr', 'account'),
'help' => true,
'disabled' => get_config('wysiwyg'),
);
$elements['maildisabled'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->maildisabled,
'title' => get_string('email'),
'help' => true,
);
$elements['messages'] = array(
'type' => 'radio',
'defaultvalue' => $prefs->messages,
'title' => get_string('messagesdescr', 'account'),
'separator' => '<br>',
'options' => array(
'nobody' => get_string('messagesnobody', 'account'),
'friends' => get_string('messagesfriends', 'account'),
'allow' => get_string('messagesallow', 'account'),
),
'help' => true,
);
$languages = get_languages();
$elements['lang'] = array(
'type' => 'select',
'defaultvalue' => $prefs->lang,
'title' => get_string('language', 'account'),
'options' => array_merge(array('default' => get_string('sitedefault', 'admin') . ' (' . $languages[get_config('lang')] . ')'), $languages),
'help' => true,
'ignore' => count($languages) < 2,
);
$elements['addremovecolumns'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->addremovecolumns,
'title' => get_string('showviewcolumns', 'account'),
'help' => 'true'
);
// TODO: add a way for plugins (like blog!) to have account preferences
$elements['multipleblogs'] = array(
'type' => 'checkbox',
'title'=> get_string('enablemultipleblogs' ,'account'),
'description' => get_string('enablemultipleblogsdescription', 'account'),
'defaultvalue' => $prefs->multipleblogs,
);
if (get_config('showtagssideblock')) {
$elements['tagssideblockmaxtags'] = array(
'type' => 'text',
'size' => 4,
'title' => get_string('tagssideblockmaxtags', 'account'),
'description' => get_string('tagssideblockmaxtagsdescription', 'account'),
'defaultvalue' => isset($prefs->tagssideblockmaxtags) ? $prefs->tagssideblockmaxtags : get_config('tagssideblockmaxtags'),
'rules' => array('integer' => true, 'minvalue' => 0, 'maxvalue' => 1000),
);
}
if (get_config('userscanhiderealnames')) {
$elements['hiderealname'] = array(
'type' => 'checkbox',
'title' => get_string('hiderealname', 'account'),
'description' => get_string('hiderealnamedescription', 'account'),
'defaultvalue' => $prefs->hiderealname,
);
}
if (get_config('homepageinfo')) {
$elements['showhomeinfo'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->showhomeinfo,
'title' => get_string('showhomeinfo', 'account'),
'help' => 'true'
);
}
if (get_config('allowmobileuploads')) {
$elements['mobileuploadtoken'] = array(
'type' => 'text',
'title' => get_string('mobileuploadtoken', 'account'),
'description' => get_string('mobileuploadtokendescription', 'account'),
'defaultvalue' => isset($prefs->mobileuploadtoken) ? $prefs->mobileuploadtoken : get_config('mobileuploadtoken')
);
}
return $elements;
}
function set_profile_field($userid, $field, $value) {
safe_require('artefact', 'internal');
......@@ -1712,9 +1811,10 @@ function addfriend_submit(Pieform $form, $values) {
* @param string $institution Institution the user should joined to
* @param stdclass $remoteauth authinstance record for a remote authinstance
* @param string $remotename username on the remote site
* @param array $accountprefs user account preferences to set
* @return integer id of the new user
*/
function create_user($user, $profile=array(), $institution=null, $remoteauth=null, $remotename=null) {
function create_user($user, $profile=array(), $institution=null, $remoteauth=null, $remotename=null, $accountprefs=array()) {
db_begin();
if ($user instanceof User) {
......@@ -1773,6 +1873,16 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
));
}
// Set account preferences
if (!empty($accountprefs)) {
$expectedprefs = expected_account_preferences();
foreach ($expectedprefs as $eprefkey => $epref) {
if (isset($accountprefs[$eprefkey]) && $accountprefs[$eprefkey] != $epref) {
set_account_preference($user->id, $eprefkey, $accountprefs[$eprefkey]);
}
}
}
// Copy site views to the new user's profile
$checkviewaccess = !$user->newuser;
$userobj = new User();
......@@ -1792,9 +1902,10 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
* @param object $user stdclass for the usr table
* @param object $profile profile field/values to set
* @param string $remotename username on the remote site
* @param array $accountprefs user account preferences to set
* @return array list of updated fields
*/
function update_user($user, $profile, $remotename=null) {
function update_user($user, $profile, $remotename=null, $accountprefs=array()) {
require_once(get_config('docroot') . 'auth/session.php');
if (!empty($user->id)) {
......@@ -1849,6 +1960,17 @@ function update_user($user, $profile, $remotename=null) {
));
}
// Update account preferences
if (!empty($accountprefs)) {
$expectedprefs = expected_account_preferences();
foreach ($expectedprefs as $eprefkey => $epref) {
if (isset($accountprefs[$eprefkey]) && $accountprefs[$eprefkey] != get_account_preference($userid, $eprefkey)) {
set_account_preference($userid, $eprefkey, $accountprefs[$eprefkey]);
$updated[$eprefkey] = $accountprefs[$eprefkey];
}
}
}
db_commit();
return $updated;
......
......@@ -67,7 +67,31 @@ echo $form_tag;
</tr>
</tbody>
</table>
<br>
<?php
// Render account preferences with a renderer (inside this template :D)
$accountprefs = (object) expected_account_preferences();
$accountprefs = array_keys(general_account_prefs_form_elements($accountprefs));
$fieldset_elements = array();
foreach ($accountprefs as $p) {
$fieldset_elements[] = $elements[$p];
}
$accountoptions_fieldset = array(
'type' => 'fieldset',
'legend' => get_string('accountoptionsdesc', 'account'),
'collapsible' => true,
'collapsed' => true,
'elements' => $fieldset_elements,
);
$this->include_plugin('renderer', $this->data['renderer']);
$this->include_plugin('element', 'fieldset');
$this->build_element_html($accountoptions_fieldset);
echo pieform_render_element($this, $accountoptions_fieldset);
echo $hidden_elements;
echo '</form>';
?>
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