- Profile module improvements:
+ Made it possible to define the page title of the user listing pages. + Used form_group()s for the profile administration page. + Fixed bug in database/updates.inc.4.5.x
parent
297dc76df0
commit
b5c441a926
|
@ -322,6 +322,7 @@ CREATE TABLE profile_fields (
|
|||
name varchar(128) default NULL,
|
||||
explanation TEXT default NULL,
|
||||
category varchar(255) default NULL,
|
||||
page varchar(255) default NULL,
|
||||
type varchar(128) default NULL,
|
||||
weight tinyint(1) DEFAULT '0' NOT NULL,
|
||||
overview tinyint(1) DEFAULT '0' NOT NULL,
|
||||
|
|
|
@ -51,7 +51,8 @@ $sql_updates = array(
|
|||
"2004-01-13" => "update_77",
|
||||
"2004-02-03" => "update_78",
|
||||
"2004-02-21" => "update_79",
|
||||
"2004-03-11: first update since Drupal 4.4.0 release" => "update_80"
|
||||
"2004-03-11: first update since Drupal 4.4.0 release" => "update_80",
|
||||
"2004-02-20" => "update_81"
|
||||
);
|
||||
|
||||
function update_32() {
|
||||
|
@ -764,15 +765,15 @@ function update_79() {
|
|||
function update_80() {
|
||||
|
||||
// Add a 'created' field to the users table:
|
||||
update_sql('ALTER TABLE {users} ADD created INT(11) NOT NULL');
|
||||
update_sql('ALTER TABLE {users} CHANGE timestamp changed INT(11) NOT NULL');
|
||||
$ret[] = update_sql('ALTER TABLE {users} ADD created INT(11) NOT NULL');
|
||||
$ret[] = update_sql('ALTER TABLE {users} CHANGE timestamp changed INT(11) NOT NULL');
|
||||
|
||||
// Add some indices to speed up the update process:
|
||||
update_sql('ALTER TABLE {comments} ADD index (timestamp)');
|
||||
update_sql('ALTER TABLE {node} ADD index (created)');
|
||||
$ret[] = update_sql('ALTER TABLE {comments} ADD index (timestamp)');
|
||||
$ret[] = update_sql('ALTER TABLE {node} ADD index (created)');
|
||||
|
||||
// Assign everyone a created timestamp to begin with:
|
||||
update_sql("UPDATE {users} SET created = changed WHERE created = ''");
|
||||
$ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = ''");
|
||||
|
||||
// Print a status message:"
|
||||
print '<p>Note: this might take a while ...</p>';
|
||||
|
@ -798,7 +799,7 @@ function update_80() {
|
|||
}
|
||||
|
||||
// Add profile module related tables:
|
||||
update_sql("CREATE TABLE {profile_fields} (
|
||||
$ret[] = update_sql("CREATE TABLE {profile_fields} (
|
||||
fid int(10) NOT NULL auto_increment,
|
||||
title varchar(255) default NULL,
|
||||
name varchar(128) default NULL,
|
||||
|
@ -813,7 +814,7 @@ function update_80() {
|
|||
PRIMARY KEY (fid)
|
||||
);");
|
||||
|
||||
update_sql("CREATE TABLE {profile_values} (
|
||||
$ret[] = update_sql("CREATE TABLE {profile_values} (
|
||||
fid int(11) unsigned default '0',
|
||||
uid int(11) unsigned default '0',
|
||||
value text,
|
||||
|
@ -879,8 +880,16 @@ function update_80() {
|
|||
// Save the update record:
|
||||
user_save($account, $edit);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function update_81() {
|
||||
$ret[] = update_sql('ALTER TABLE {profile_fields} ADD page varchar(255) default NULL');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function update_sql($sql) {
|
||||
$edit = $_POST["edit"];
|
||||
$result = db_query($sql);
|
||||
|
|
|
@ -32,7 +32,7 @@ function profile_browse() {
|
|||
$value = arg(2) ? arg(2) : 1;
|
||||
|
||||
// Determine the field to group users by:
|
||||
$field = db_fetch_object(db_query("SELECT DISTINCT(f.fid), f.type, f.title FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE f.name = '%s' AND v.value = '%s' ORDER BY f.category, f.weight", arg(1), $value));
|
||||
$field = db_fetch_object(db_query("SELECT DISTINCT(f.fid), f.type, f.title, f.page FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE f.name = '%s' AND v.value = '%s' ORDER BY f.category, f.weight", arg(1), $value));
|
||||
|
||||
if ($field->fid) {
|
||||
// Compile a list of fields to show:
|
||||
|
@ -45,18 +45,19 @@ function profile_browse() {
|
|||
// Extract the affected users:
|
||||
$result = pager_query("SELECT u.uid FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = $field->fid AND v.value = '". check_query($value) ."' ORDER BY u.changed DESC", 20);
|
||||
|
||||
$output = '';
|
||||
$output = '<div id="profile">';
|
||||
while ($account = db_fetch_object($result)) {
|
||||
$output .= theme('profile_profile', user_load(array('uid' => $account->uid)), $fields);
|
||||
}
|
||||
$output .= theme('pager', NULL, 20);
|
||||
|
||||
if ($field->type == "selection") {
|
||||
$title = arg(2);
|
||||
$title = strtr($field->page, array('%value' => arg(2)));
|
||||
}
|
||||
else {
|
||||
$title = $field->title;
|
||||
$title = $field->page;
|
||||
}
|
||||
$output .= "</div>";
|
||||
|
||||
print theme('page', $output, $title);
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ function profile_admin_add($type) {
|
|||
drupal_set_message($error, 'error');
|
||||
}
|
||||
else {
|
||||
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options']);
|
||||
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options'], $data['page']);
|
||||
|
||||
drupal_set_message(t('the field has been created.'));
|
||||
}
|
||||
|
@ -214,7 +215,7 @@ function profile_admin_edit($fid) {
|
|||
|
||||
}
|
||||
else {
|
||||
db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $fid);
|
||||
db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $data['page'], $fid);
|
||||
|
||||
drupal_set_message(t('the field has been updated.'));
|
||||
}
|
||||
|
@ -234,18 +235,27 @@ function profile_admin_delete($fid) {
|
|||
|
||||
function _profile_field_form($type, $edit = array()) {
|
||||
|
||||
$output = form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t("The title of the new field. The title will be shown to the user. An example title is 'Favorite color'."), NULL, FORM_REQUIRED);
|
||||
$output .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t("The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
|
||||
$group = form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t("The category the new field should be part of. Categories are used to group fields logically. An example category is 'Personal information'."));
|
||||
$group .= form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t("The title of the new field. The title will be shown to the user. An example title is 'Favorite color'."));
|
||||
$group .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t("The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
|
||||
Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is 'profile_favorite_color' or perhaps just 'profile_color'."));
|
||||
$output .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t("An optional explanation to go with the new field. The explanation will be shown to the user."));
|
||||
$output .= form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t("The category the new field should be part of. Categories are used to group fields logically. An example category is 'Personal information'."));
|
||||
$output .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category."));
|
||||
$output .= form_checkbox(t('Display this field in member lists'), 'overview', 1, $edit['overview']);
|
||||
|
||||
$group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t("An optional explanation to go with the new field. The explanation will be shown to the user."));
|
||||
if ($type == 'selection') {
|
||||
$output .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc."));
|
||||
$group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc."));
|
||||
}
|
||||
$group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category."));
|
||||
$output = form_group(t('Field settings'), $group);
|
||||
|
||||
$group = '';
|
||||
if ($type == 'selection') {
|
||||
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is 'People whose favorite color is %value'."));
|
||||
}
|
||||
else {
|
||||
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field."));
|
||||
}
|
||||
$group .= form_checkbox(t('Should this field be shown on the member listing pages.'), 'overview', 1, $edit['overview']);
|
||||
|
||||
$output .= form_group(t('Browsability'), $group);
|
||||
$output .= form_submit(t('Save field'));
|
||||
|
||||
return form($output);
|
||||
|
@ -280,10 +290,10 @@ function theme_profile_profile($user, $fields = array()) {
|
|||
foreach ($fields as $field) {
|
||||
if ($user->{$field->name}) {
|
||||
if ($field->type == 'checkbox') {
|
||||
$output .= "<div class=\"field\">". $field->title ."</div>";
|
||||
$output .= " <div class=\"field\">". $field->title ."</div>\n";
|
||||
}
|
||||
else {
|
||||
$output .= "<div class=\"field\">". $user->{$field->name} ."</div>";
|
||||
$output .= " <div class=\"field\">". $user->{$field->name} ."</div>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ function profile_browse() {
|
|||
$value = arg(2) ? arg(2) : 1;
|
||||
|
||||
// Determine the field to group users by:
|
||||
$field = db_fetch_object(db_query("SELECT DISTINCT(f.fid), f.type, f.title FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE f.name = '%s' AND v.value = '%s' ORDER BY f.category, f.weight", arg(1), $value));
|
||||
$field = db_fetch_object(db_query("SELECT DISTINCT(f.fid), f.type, f.title, f.page FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE f.name = '%s' AND v.value = '%s' ORDER BY f.category, f.weight", arg(1), $value));
|
||||
|
||||
if ($field->fid) {
|
||||
// Compile a list of fields to show:
|
||||
|
@ -45,18 +45,19 @@ function profile_browse() {
|
|||
// Extract the affected users:
|
||||
$result = pager_query("SELECT u.uid FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = $field->fid AND v.value = '". check_query($value) ."' ORDER BY u.changed DESC", 20);
|
||||
|
||||
$output = '';
|
||||
$output = '<div id="profile">';
|
||||
while ($account = db_fetch_object($result)) {
|
||||
$output .= theme('profile_profile', user_load(array('uid' => $account->uid)), $fields);
|
||||
}
|
||||
$output .= theme('pager', NULL, 20);
|
||||
|
||||
if ($field->type == "selection") {
|
||||
$title = arg(2);
|
||||
$title = strtr($field->page, array('%value' => arg(2)));
|
||||
}
|
||||
else {
|
||||
$title = $field->title;
|
||||
$title = $field->page;
|
||||
}
|
||||
$output .= "</div>";
|
||||
|
||||
print theme('page', $output, $title);
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ function profile_admin_add($type) {
|
|||
drupal_set_message($error, 'error');
|
||||
}
|
||||
else {
|
||||
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options']);
|
||||
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options'], $data['page']);
|
||||
|
||||
drupal_set_message(t('the field has been created.'));
|
||||
}
|
||||
|
@ -214,7 +215,7 @@ function profile_admin_edit($fid) {
|
|||
|
||||
}
|
||||
else {
|
||||
db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $fid);
|
||||
db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $data['page'], $fid);
|
||||
|
||||
drupal_set_message(t('the field has been updated.'));
|
||||
}
|
||||
|
@ -234,18 +235,27 @@ function profile_admin_delete($fid) {
|
|||
|
||||
function _profile_field_form($type, $edit = array()) {
|
||||
|
||||
$output = form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t("The title of the new field. The title will be shown to the user. An example title is 'Favorite color'."), NULL, FORM_REQUIRED);
|
||||
$output .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t("The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
|
||||
$group = form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t("The category the new field should be part of. Categories are used to group fields logically. An example category is 'Personal information'."));
|
||||
$group .= form_textfield(t('Title'), 'title', $edit['title'], 70, 128, t("The title of the new field. The title will be shown to the user. An example title is 'Favorite color'."));
|
||||
$group .= form_textfield(t('Form name'), 'name', $edit['name'], 70, 128, t("The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
|
||||
Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is 'profile_favorite_color' or perhaps just 'profile_color'."));
|
||||
$output .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t("An optional explanation to go with the new field. The explanation will be shown to the user."));
|
||||
$output .= form_textfield(t('Category'), 'category', $edit['category'], 70, 128, t("The category the new field should be part of. Categories are used to group fields logically. An example category is 'Personal information'."));
|
||||
$output .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category."));
|
||||
$output .= form_checkbox(t('Display this field in member lists'), 'overview', 1, $edit['overview']);
|
||||
|
||||
$group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 70, 3, t("An optional explanation to go with the new field. The explanation will be shown to the user."));
|
||||
if ($type == 'selection') {
|
||||
$output .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc."));
|
||||
$group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc."));
|
||||
}
|
||||
$group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category."));
|
||||
$output = form_group(t('Field settings'), $group);
|
||||
|
||||
$group = '';
|
||||
if ($type == 'selection') {
|
||||
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is 'People whose favorite color is %value'."));
|
||||
}
|
||||
else {
|
||||
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t("The title of the page showing all users with the specified field."));
|
||||
}
|
||||
$group .= form_checkbox(t('Should this field be shown on the member listing pages.'), 'overview', 1, $edit['overview']);
|
||||
|
||||
$output .= form_group(t('Browsability'), $group);
|
||||
$output .= form_submit(t('Save field'));
|
||||
|
||||
return form($output);
|
||||
|
@ -280,10 +290,10 @@ function theme_profile_profile($user, $fields = array()) {
|
|||
foreach ($fields as $field) {
|
||||
if ($user->{$field->name}) {
|
||||
if ($field->type == 'checkbox') {
|
||||
$output .= "<div class=\"field\">". $field->title ."</div>";
|
||||
$output .= " <div class=\"field\">". $field->title ."</div>\n";
|
||||
}
|
||||
else {
|
||||
$output .= "<div class=\"field\">". $user->{$field->name} ."</div>";
|
||||
$output .= " <div class=\"field\">". $user->{$field->name} ."</div>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue