summaryrefslogtreecommitdiff
path: root/modules/profile/profile.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2006-11-12 19:33:30 +0000
committerDries Buytaert <dries@buytaert.net>2006-11-12 19:33:30 +0000
commitab43e83eb4acefc8096c54a3294fd17d93c88bb8 (patch)
tree1e1515e6f9da6e667510f9cf78c25ab981cb5061 /modules/profile/profile.module
parent926e6830d6e25631d4965aac93afd86640d8b5a3 (diff)
downloadbrdo-ab43e83eb4acefc8096c54a3294fd17d93c88bb8.tar.gz
brdo-ab43e83eb4acefc8096c54a3294fd17d93c88bb8.tar.bz2
- Patch #88402 by chx et al: made it possible to remove profile field.
Diffstat (limited to 'modules/profile/profile.module')
-rw-r--r--modules/profile/profile.module59
1 files changed, 24 insertions, 35 deletions
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 629514536..c460aa626 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -525,13 +525,7 @@ function profile_load_profile(&$user) {
}
function profile_save_profile(&$edit, &$user, $category) {
- if ((arg(0) == 'user' && arg(1) == 'register') || (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'create')) {
- $result = db_query('SELECT fid, name, type FROM {profile_fields} WHERE register = 1 AND visibility != %d ORDER BY category, weight', PROFILE_HIDDEN);
- }
- else {
- $result = db_query("SELECT fid, name, type FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') AND visibility != %d", $category, PROFILE_HIDDEN);
- // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
- }
+ $result = _profile_get_fields($category);
while ($field = db_fetch_object($result)) {
if (_profile_field_serialize($field->type)) {
$edit[$field->name] = serialize($edit[$field->name]);
@@ -628,20 +622,7 @@ function _profile_form_explanation($field) {
}
function profile_form_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);
- }
- elseif (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'user' && arg(3) == 'create') {
- $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
- }
- elseif (user_access('administer users')) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
- }
- else {
- $result = db_query("SELECT * FROM {profile_fields} WHERE visibility != %d AND LOWER(category) = LOWER('%s') ORDER BY weight", PROFILE_HIDDEN, $category);
- // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
- }
-
+ $result = _profile_get_fields($category);
$w = 0;
while ($field = db_fetch_object($result)) {
$category = $field->category;
@@ -742,20 +723,7 @@ function _profile_update_user_fields($fields, $account) {
}
function profile_validate_profile($edit, $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);
- }
- elseif (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'create') {
- $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
- }
- elseif (user_access('administer users')) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
- }
- else {
- $result = db_query("SELECT * FROM {profile_fields} WHERE visibility != %d AND LOWER(category) = LOWER('%s') ORDER BY weight", PROFILE_HIDDEN, $category);
- // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
- }
-
+ $result = _profile_get_fields($category);
while ($field = db_fetch_object($result)) {
if ($edit[$field->name]) {
if ($field->type == 'url') {
@@ -830,6 +798,27 @@ function _profile_field_serialize($type = NULL) {
return $type == 'date';
}
+function _profile_get_fields($category) {
+ $args = array();
+ $sql = 'SELECT * FROM {profile_fields} WHERE ';
+ $filters = array();
+ if ((arg(0) == 'user' && arg(1) == 'register') || (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'create')) {
+ $filters[] = 'register = 1';
+ }
+ else {
+ // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
+ $filters[] = "LOWER(category) = LOWER('%s')";
+ $args[] = $category;
+ }
+ if (!user_access('administer users')) {
+ $filters[] = 'visibility != %d';
+ $args[] = PROFILE_HIDDEN;
+ }
+ $sql .= implode(' AND ', $filters);
+ $sql .= ' ORDER BY category, weight';
+ return db_query($sql, $args);
+}
+
/**
* Retrieve a pipe delimited string of autocomplete suggestions for profile categories
*/