diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 1de9ad1ca6e..a5903938cb7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,7 @@ Drupal x.x.x, xxxx-xx-xx (development version) ------------------------ +- usability: + * added support for auto-complete forms (AJAX) to user profiles. Drupal 4.7.0, 2006-05-01 ------------------------ diff --git a/LICENSE.txt b/LICENSE.txt index f90922eea38..fe40b44b808 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,12 +1,12 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Programs + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it diff --git a/database/database.4.0.mysql b/database/database.4.0.mysql index b4a4dcc4f2d..dfd96323ca1 100644 --- a/database/database.4.0.mysql +++ b/database/database.4.0.mysql @@ -475,6 +475,7 @@ CREATE TABLE profile_fields ( required tinyint(1) DEFAULT '0' NOT NULL, register tinyint(1) DEFAULT '0' NOT NULL, visibility tinyint(1) DEFAULT '0' NOT NULL, + autocomplete tinyint(1) DEFAULT '0' NOT NULL, options text, KEY category (category), UNIQUE KEY name (name), diff --git a/database/database.4.1.mysql b/database/database.4.1.mysql index 52eebe6e3d5..8c2c3318f10 100644 --- a/database/database.4.1.mysql +++ b/database/database.4.1.mysql @@ -506,6 +506,7 @@ CREATE TABLE profile_fields ( required tinyint(1) DEFAULT '0' NOT NULL, register tinyint(1) DEFAULT '0' NOT NULL, visibility tinyint(1) DEFAULT '0' NOT NULL, + autocomplete tinyint(1) DEFAULT '0' NOT NULL, options text, KEY category (category), UNIQUE KEY name (name), diff --git a/database/database.pgsql b/database/database.pgsql index f684192552c..c2449b59110 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -482,6 +482,7 @@ CREATE TABLE profile_fields ( required smallint DEFAULT '0' NOT NULL, register smallint DEFAULT '0' NOT NULL, visibility smallint DEFAULT '0' NOT NULL, + autocomplete smallint DEFAULT '0' NOT NULL, options text, UNIQUE (name), PRIMARY KEY (fid) diff --git a/database/updates.inc b/database/updates.inc index 658f7103d69..ecb8384eb72 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -1973,3 +1973,17 @@ function system_update_180() { return $ret; } + +function system_update_181() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {profile_fields} ADD autocomplete TINYINT(1) NOT NULL AFTER visibility ;"); + break; + case 'pgsql': + db_add_column($ret, 'profile_fields', 'autocomplete', 'smallint'); + break; + } + return $ret; +} diff --git a/modules/profile.module b/modules/profile.module index 720385e6945..b269c268851 100644 --- a/modules/profile.module +++ b/modules/profile.module @@ -79,6 +79,10 @@ function profile_menu($may_cache) { 'title' => t('delete field'), 'callback' => 'profile_field_delete', 'type' => MENU_CALLBACK); + $items[] = array('path' => 'profile/autocomplete', 'title' => t('profile autocomplete'), + 'callback' => 'profile_autocomplete', + 'access' => 1, + 'type' => MENU_CALLBACK); } return $items; @@ -271,6 +275,10 @@ Unless you know what you are doing, it is highly recommended that you prefix the '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'), ); } + $form['fields']['autocomplete'] = array('#type' => 'checkbox', + '#title' => t('Form will auto-complete while user is typing.'), + '#default_value' => $edit['autocomplete'], + ); $form['fields']['required'] = array('#type' => 'checkbox', '#title' => t('The user must enter a value.'), '#default_value' => $edit['required'], @@ -326,13 +334,13 @@ function profile_field_form_validate($form_id, $form_values) { */ function profile_field_form_submit($form_id, $form_values) { if (!isset($form_values['fid'])) { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page']); drupal_set_message(t('The field has been created.')); watchdog('profile', t('Profile field %field added under category %category.', array('%field' => theme('placeholder', $form_values['title']), '%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/settings/profile')); } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page'], $form_values['fid']); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page'], $form_values['fid']); drupal_set_message(t('The field has been updated.')); } @@ -640,6 +648,9 @@ function profile_form_profile($edit, $user, $category) { '#description' => _profile_form_explanation($field), '#required' => $field->required, ); + if ($field->autocomplete) { + $fields[$category][$field->name]['#autocomplete_path'] = "profile/autocomplete/". $field->fid; + } break; case 'textarea': $fields[$category][$field->name] = array('#type' => 'textarea', @@ -694,6 +705,22 @@ function profile_form_profile($edit, $user, $category) { return $fields; } +/** + * Callback to allow autocomplete of profile text fields. + */ +function profile_autocomplete($field, $string) { + if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { + $matches = array(); + $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); + while ($data = db_fetch_object($result)) { + $matches[$data->value] = check_plain($data->value); + } + + print drupal_to_js($matches); + } + exit(); +} + /** * Helper function: update an array of user fields by calling profile_view_field */ diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 720385e6945..b269c268851 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -79,6 +79,10 @@ function profile_menu($may_cache) { 'title' => t('delete field'), 'callback' => 'profile_field_delete', 'type' => MENU_CALLBACK); + $items[] = array('path' => 'profile/autocomplete', 'title' => t('profile autocomplete'), + 'callback' => 'profile_autocomplete', + 'access' => 1, + 'type' => MENU_CALLBACK); } return $items; @@ -271,6 +275,10 @@ Unless you know what you are doing, it is highly recommended that you prefix the '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'), ); } + $form['fields']['autocomplete'] = array('#type' => 'checkbox', + '#title' => t('Form will auto-complete while user is typing.'), + '#default_value' => $edit['autocomplete'], + ); $form['fields']['required'] = array('#type' => 'checkbox', '#title' => t('The user must enter a value.'), '#default_value' => $edit['required'], @@ -326,13 +334,13 @@ function profile_field_form_validate($form_id, $form_values) { */ function profile_field_form_submit($form_id, $form_values) { if (!isset($form_values['fid'])) { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page']); drupal_set_message(t('The field has been created.')); watchdog('profile', t('Profile field %field added under category %category.', array('%field' => theme('placeholder', $form_values['title']), '%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/settings/profile')); } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page'], $form_values['fid']); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page'], $form_values['fid']); drupal_set_message(t('The field has been updated.')); } @@ -640,6 +648,9 @@ function profile_form_profile($edit, $user, $category) { '#description' => _profile_form_explanation($field), '#required' => $field->required, ); + if ($field->autocomplete) { + $fields[$category][$field->name]['#autocomplete_path'] = "profile/autocomplete/". $field->fid; + } break; case 'textarea': $fields[$category][$field->name] = array('#type' => 'textarea', @@ -694,6 +705,22 @@ function profile_form_profile($edit, $user, $category) { return $fields; } +/** + * Callback to allow autocomplete of profile text fields. + */ +function profile_autocomplete($field, $string) { + if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { + $matches = array(); + $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); + while ($data = db_fetch_object($result)) { + $matches[$data->value] = check_plain($data->value); + } + + print drupal_to_js($matches); + } + exit(); +} + /** * Helper function: update an array of user fields by calling profile_view_field */ diff --git a/modules/upload.module b/modules/upload.module index 3535ea56edc..c575d1d7938 100644 --- a/modules/upload.module +++ b/modules/upload.module @@ -107,20 +107,20 @@ function upload_settings() { $upload_usersize_default = variable_get('upload_usersize_default', 10); $form['settings_general'] = array( - '#type' => 'fieldset', - '#title' => t('General settings'), + '#type' => 'fieldset', + '#title' => t('General settings'), '#collapsible' => TRUE, ); $form['settings_general']['upload_max_resolution'] = array( - '#type' => 'textfield', - '#title' => t('Maximum resolution for uploaded images'), + '#type' => 'textfield', + '#title' => t('Maximum resolution for uploaded images'), '#default_value' => variable_get('upload_max_resolution', 0), - '#size' => 15, - '#maxlength' => 10, + '#size' => 15, + '#maxlength' => 10, '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'), ); $form['settings_general']['upload_list_default'] = array( - '#type' => 'select', + '#type' => 'select', '#title' => t('List files by default'), '#default_value' => variable_get('upload_list_default', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), @@ -128,26 +128,26 @@ function upload_settings() { ); $form['settings_general']['upload_extensions_default'] = array( - '#type' => 'textfield', - '#title' => t('Default permitted file extensions'), + '#type' => 'textfield', + '#title' => t('Default permitted file extensions'), '#default_value' => $upload_extensions_default, - '#maxlength' => 255, + '#maxlength' => 255, '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'), ); $form['settings_general']['upload_uploadsize_default'] = array( - '#type' => 'textfield', - '#title' => t('Default maximum file size per upload'), + '#type' => 'textfield', + '#title' => t('Default maximum file size per upload'), '#default_value' => $upload_uploadsize_default, - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The default maximum file size a user can upload (in megabytes).'), ); $form['settings_general']['upload_usersize_default'] = array( - '#type' => 'textfield', - '#title' => t('Default total file size per user'), + '#type' => 'textfield', + '#title' => t('Default total file size per user'), '#default_value' => $upload_usersize_default, - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The default maximum size of all files a user can have on the site (in megabytes).'), ); @@ -155,32 +155,32 @@ function upload_settings() { foreach ($roles as $rid => $role) { $form["settings_role_$rid"] = array( - '#type' => 'fieldset', - '#title' => t('Settings for %role', array('%role' => theme('placeholder', $role))), - '#collapsible' => TRUE, + '#type' => 'fieldset', + '#title' => t('Settings for %role', array('%role' => theme('placeholder', $role))), + '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form["settings_role_$rid"]["upload_extensions_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Permitted file extensions'), + '#type' => 'textfield', + '#title' => t('Permitted file extensions'), '#default_value' => variable_get("upload_extensions_$rid", $upload_extensions_default), - '#maxlength' => 255, + '#maxlength' => 255, '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'), ); $form["settings_role_$rid"]["upload_uploadsize_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Maximum file size per upload'), + '#type' => 'textfield', + '#title' => t('Maximum file size per upload'), '#default_value' => variable_get("upload_uploadsize_$rid", $upload_uploadsize_default), - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The maximum size of a file a user can upload (in megabytes).'), ); $form["settings_role_$rid"]["upload_usersize_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Total file size per user'), + '#type' => 'textfield', + '#title' => t('Total file size per user'), '#default_value' => variable_get("upload_usersize_$rid", $upload_usersize_default), - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The maximum size of all files a user can have on the site (in megabytes).'), ); } diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 3535ea56edc..c575d1d7938 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -107,20 +107,20 @@ function upload_settings() { $upload_usersize_default = variable_get('upload_usersize_default', 10); $form['settings_general'] = array( - '#type' => 'fieldset', - '#title' => t('General settings'), + '#type' => 'fieldset', + '#title' => t('General settings'), '#collapsible' => TRUE, ); $form['settings_general']['upload_max_resolution'] = array( - '#type' => 'textfield', - '#title' => t('Maximum resolution for uploaded images'), + '#type' => 'textfield', + '#title' => t('Maximum resolution for uploaded images'), '#default_value' => variable_get('upload_max_resolution', 0), - '#size' => 15, - '#maxlength' => 10, + '#size' => 15, + '#maxlength' => 10, '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'), ); $form['settings_general']['upload_list_default'] = array( - '#type' => 'select', + '#type' => 'select', '#title' => t('List files by default'), '#default_value' => variable_get('upload_list_default', 1), '#options' => array(0 => t('No'), 1 => t('Yes')), @@ -128,26 +128,26 @@ function upload_settings() { ); $form['settings_general']['upload_extensions_default'] = array( - '#type' => 'textfield', - '#title' => t('Default permitted file extensions'), + '#type' => 'textfield', + '#title' => t('Default permitted file extensions'), '#default_value' => $upload_extensions_default, - '#maxlength' => 255, + '#maxlength' => 255, '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'), ); $form['settings_general']['upload_uploadsize_default'] = array( - '#type' => 'textfield', - '#title' => t('Default maximum file size per upload'), + '#type' => 'textfield', + '#title' => t('Default maximum file size per upload'), '#default_value' => $upload_uploadsize_default, - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The default maximum file size a user can upload (in megabytes).'), ); $form['settings_general']['upload_usersize_default'] = array( - '#type' => 'textfield', - '#title' => t('Default total file size per user'), + '#type' => 'textfield', + '#title' => t('Default total file size per user'), '#default_value' => $upload_usersize_default, - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The default maximum size of all files a user can have on the site (in megabytes).'), ); @@ -155,32 +155,32 @@ function upload_settings() { foreach ($roles as $rid => $role) { $form["settings_role_$rid"] = array( - '#type' => 'fieldset', - '#title' => t('Settings for %role', array('%role' => theme('placeholder', $role))), - '#collapsible' => TRUE, + '#type' => 'fieldset', + '#title' => t('Settings for %role', array('%role' => theme('placeholder', $role))), + '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form["settings_role_$rid"]["upload_extensions_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Permitted file extensions'), + '#type' => 'textfield', + '#title' => t('Permitted file extensions'), '#default_value' => variable_get("upload_extensions_$rid", $upload_extensions_default), - '#maxlength' => 255, + '#maxlength' => 255, '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'), ); $form["settings_role_$rid"]["upload_uploadsize_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Maximum file size per upload'), + '#type' => 'textfield', + '#title' => t('Maximum file size per upload'), '#default_value' => variable_get("upload_uploadsize_$rid", $upload_uploadsize_default), - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The maximum size of a file a user can upload (in megabytes).'), ); $form["settings_role_$rid"]["upload_usersize_$rid"] = array( - '#type' => 'textfield', - '#title' => t('Total file size per user'), + '#type' => 'textfield', + '#title' => t('Total file size per user'), '#default_value' => variable_get("upload_usersize_$rid", $upload_usersize_default), - '#size' => 5, - '#maxlength' => 5, + '#size' => 5, + '#maxlength' => 5, '#description' => t('The maximum size of all files a user can have on the site (in megabytes).'), ); }