From fa7f750c60db0a65ad69d6fd5caaccd0ce057cb8 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 14 Feb 2011 20:10:50 +0100 Subject: [PATCH] MDL-25778 add defaultcity option This is based on patch by Jonathan Harker. --- admin/settings/location.php | 1 + admin/uploaduser.php | 4 ++++ auth/db/auth.php | 4 ++++ auth/ldap/auth.php | 8 ++++++++ lang/en/admin.php | 2 ++ login/signup_form.php | 3 +++ user/editlib.php | 4 +++- 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/admin/settings/location.php b/admin/settings/location.php index 4ef1f6fc8029c..6e33a51085c20 100644 --- a/admin/settings/location.php +++ b/admin/settings/location.php @@ -10,6 +10,7 @@ $options[99] = get_string('timezonenotforced', 'admin'); $temp->add(new admin_setting_configselect('forcetimezone', get_string('forcetimezone', 'admin'), get_string('helpforcetimezone', 'admin'), 99, $options)); $temp->add(new admin_settings_country_select('country', get_string('country', 'admin'), get_string('configcountry', 'admin'), 0)); + $temp->add(new admin_setting_configtext('defaultcity', get_string('defaultcity', 'admin'), get_string('defaultcity_help', 'admin'), '')); $temp->add(new admin_setting_heading('iplookup', get_string('iplookup', 'admin'), get_string('iplookupinfo', 'admin'))); $temp->add(new admin_setting_configfile('geoipfile', get_string('geoipfile', 'admin'), get_string('configgeoipfile', 'admin', $CFG->dataroot.'/geoip/'), $CFG->dataroot.'/geoip/GeoLiteCity.dat')); diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 5ee0e8a15d20b..b25f60970ae82 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -572,6 +572,10 @@ $user->timemodified = time(); $user->timecreated = time(); + if (!empty($CFG->defaultcity) and !property_exists($user, 'city')) { + $user->city = $CFG->defaultcity; + } + if (isset($user->auth) && empty($user->auth)) { $user->auth = 'manual'; } diff --git a/auth/db/auth.php b/auth/db/auth.php index 4f875b53239ef..29befd901288f 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -358,6 +358,10 @@ function sync_users($do_updates=false) { echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; } else { + if (!empty($CFG->defaultcity) and !property_exists($user, 'city')) { + $user->city = $CFG->defaultcity; + } + $id = $DB->insert_record ('user',$user); // it is truly a new user echo "\t"; print_string('auth_dbinsertuser','auth_db',array('name'=>$user->username, 'id'=>$id)); echo "\n"; // if relevant, tag for password generation diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index d9cd436d4ce2e..d2d8b0126889e 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -490,6 +490,10 @@ function user_signup($user, $notify=true) { print_error('auth_ldap_create_error', 'auth_ldap'); } + if (!empty($CFG->defaultcity) and !property_exists($user, 'city')) { + $user->city = $CFG->defaultcity; + } + $user->id = $DB->insert_record('user', $user); // Save any custom profile field information @@ -849,6 +853,10 @@ function sync_users($do_updates=true) { $user->lang = $CFG->lang; } + if (!empty($CFG->defaultcity) and !property_exists($user, 'city')) { + $user->city = $CFG->defaultcity; + } + $id = $DB->insert_record('user', $user); echo "\t"; print_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)); echo "\n"; if (!empty($this->config->forcechangepassword)) { diff --git a/lang/en/admin.php b/lang/en/admin.php index ce096ce3d9a4d..d2c72555bc8a7 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -429,6 +429,8 @@ $string['debugstringids'] = 'Show origin of languages strings'; $string['debugvalidators'] = 'Show validator links'; $string['defaultallowedmodules'] = 'Default allowed modules'; +$string['defaultcity'] = 'Default city'; +$string['defaultcity_help'] = 'A city entered here will be the default city when creating new user accounts.'; $string['defaulthomepage'] = 'Default home page for users'; $string['defaultrequestcategory'] = 'Default category for course requests'; $string['defaultsettinginfo'] = 'Default: {$a}'; diff --git a/login/signup_form.php b/login/signup_form.php index 373fdd712f9e4..ed1e73cf34157 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -79,6 +79,9 @@ function definition() { $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"'); $mform->setType('city', PARAM_TEXT); $mform->addRule('city', get_string('missingcity'), 'required', null, 'server'); + if (!empty($CFG->defaultcity)) { + $mform->setDefault('city', $CFG->defaultcity); + } $country = get_string_manager()->get_list_of_countries(); $default_country[''] = get_string('selectacountry'); diff --git a/user/editlib.php b/user/editlib.php index 2151512ed9982..611492429730f 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -194,7 +194,9 @@ function useredit_shared_definition(&$mform, $editoroptions = null) { $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"'); $mform->setType('city', PARAM_MULTILANG); $mform->addRule('city', $strrequired, 'required', null, 'client'); - + if (!empty($CFG->defaultcity)) { + $mform->setDefault('city', $CFG->defaultcity); + } $choices = get_string_manager()->get_list_of_countries(); $choices= array(''=>get_string('selectacountry').'...') + $choices;