Index: profile/profile.install =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.install,v retrieving revision 1.2 diff -u -r1.2 profile.install --- profile/profile.install 14 Jul 2006 01:05:09 -0000 1.2 +++ profile/profile.install 26 Jul 2006 14:22:30 -0000 @@ -18,6 +18,7 @@ register tinyint(1) DEFAULT '0' NOT NULL, visibility tinyint(1) DEFAULT '0' NOT NULL, autocomplete tinyint(1) DEFAULT '0' NOT NULL, + uniquevalue tinyint(1) DEFAULT '0' NOT NULL, options text, KEY category (category), UNIQUE KEY name (name), @@ -32,4 +33,14 @@ KEY fid (fid) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); } +} + + +function profile_update_1() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("ALTER TABLE {profile_fields} ADD uniquevalue tinyint(1) NOT NULL default '0'"); + } + return $ret; } \ No newline at end of file Index: profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.159 diff -u -r1.159 profile.module --- profile/profile.module 10 Jul 2006 19:27:52 -0000 1.159 +++ profile/profile.module 26 Jul 2006 14:22:30 -0000 @@ -171,7 +171,7 @@ case 'form': return profile_form_profile($edit, $user, $category); case 'validate': - return profile_validate_profile($edit, $category); + return profile_validate_profile($edit, $user, $category); case 'categories': return profile_categories(); case 'delete': @@ -283,6 +283,10 @@ '#title' => t('The user must enter a value.'), '#default_value' => $edit['required'], ); + $form['fields']['uniquevalue'] = array('#type' => 'checkbox', + '#title' => t('The value must be unique.'), + '#default_value' => $edit['uniquevalue'], + ); $form['fields']['register'] = array('#type' => 'checkbox', '#title' => t('Visible in user registration form.'), '#default_value' => $edit['register'], @@ -334,13 +338,13 @@ */ 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, 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']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, uniquevalue, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %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['uniquevalue'], $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, 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']); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, uniquevalue = %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['uniquevalue'], $form_values['options'], $form_values['page'], $form_values['fid']); drupal_set_message(t('The field has been updated.')); } @@ -731,7 +735,7 @@ return $fields; } -function profile_validate_profile($edit, $category) { +function profile_validate_profile($edit, $user, $category) { if (arg(0) == 'user' && arg(1) == 'register') { $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND register = 1 ORDER BY category, weight', PROFILE_HIDDEN); } @@ -753,6 +757,11 @@ form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => theme('placeholder', $field->title)))); } } + if ($field->uniquevalue) { + if (db_num_rows(db_query("SELECT uid FROM {profile_values} WHERE uid != %d AND LOWER(value) = LOWER('%s') AND fid = %d", $user->uid, $edit[$field->name], $field->fid)) > 0) { + form_set_error($field->name, t('The field %field must be unique.', array('%field' => theme('placeholder', $field->title)))); + } + } } else if ($field->required && !user_access('administer users')) { form_set_error($field->name, t('The field %field is required.', array('%field' => theme('placeholder', $field->title))));