summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/profile.module31
-rw-r--r--modules/profile/profile.module31
-rw-r--r--modules/upload.module64
-rw-r--r--modules/upload/upload.module64
4 files changed, 122 insertions, 68 deletions
diff --git a/modules/profile.module b/modules/profile.module
index 720385e69..b269c2688 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',
@@ -695,6 +706,22 @@ function profile_form_profile($edit, $user, $category) {
}
/**
+ * 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
*/
function _profile_update_user_fields($fields, $account) {
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 720385e69..b269c2688 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',
@@ -695,6 +706,22 @@ function profile_form_profile($edit, $user, $category) {
}
/**
+ * 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
*/
function _profile_update_user_fields($fields, $account) {
diff --git a/modules/upload.module b/modules/upload.module
index 3535ea56e..c575d1d79 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 3535ea56e..c575d1d79 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).'),
);
}