? advuser.replace_constant_with_t.patch
Index: advuser.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/advuser.module,v
retrieving revision 1.1
diff -u -F^f -r1.1 advuser.module
--- advuser.module 4 Jun 2006 11:00:25 -0000 1.1
+++ advuser.module 28 Aug 2006 10:48:15 -0000
@@ -2,7 +2,6 @@
define('ADVUSER_DEFAULT_NEW_MAIL', "If you want to check and edit his account go to %uri.\n\n--\n%site");
define('ADVUSER_DEFAULT_NEW_ROLES', NULL);
-define('ADVUSER_DEFAULT_NEW_SUBJECT', t('A new user (%username) has just registered on %site.'));
define('ADVUSER_DEFAULT_NEW_NOTIFY', 0);
define('ADVUSER_DEFAULT_PROFILE_FIELDS', NULL);
@@ -19,7 +18,7 @@ function advuser_menu($may_cache) {
$items = array();
if ($may_cache) {
- $items[] = array('path' => 'admin/user/advuser',
+ $items[] = array('path' => 'admin/user/advuser',
'title' => t('advanced managment'),
'callback' => 'advuser_admin_users',
'type' => MENU_LOCAL_TASK,
@@ -31,11 +30,11 @@ function advuser_menu($may_cache) {
return $items;
}
-/**
- * hook_help implementation
+/**
+ * hook_help implementation
*/
-function advuser_help($section) {
-
+function advuser_help($section) {
+
switch ($section) {
case 'admin/modules#description':
return t('Advanced user management module. Filter users and mass actions based on their filters.');
@@ -46,9 +45,9 @@ function advuser_help($section) {
** Filters
*/
function advuser_admin_filters() {
-
+
$filters = array();
-
+
/*
$result = db_query('SELECT * FROM {profile_fields} ORDER BY category, weight');
$rows = array();
@@ -60,7 +59,7 @@ function advuser_admin_filters() {
$options[$value->value] = $value->value;
}
}
-
+
// Regular filters
$filters[$field->fid] = array(
'title' =>$field->title,
@@ -74,7 +73,7 @@ function advuser_admin_filters() {
'title' =>t('E-mail'),
'where' => "u.mail = '%s'",
);
-
+
$fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
if ( is_array($fields) ) {
foreach ( $fields as $fid => $value) {
@@ -87,7 +86,7 @@ function advuser_admin_filters() {
$options[$value->value] = $value->value;
}
}
-
+
// Regular filters
$filters[$field->fid] = array(
'title' =>$field->title,
@@ -96,11 +95,11 @@ function advuser_admin_filters() {
'field_where' => 'pf.fid = ' . $field->fid .' AND pv.value = ' . "'%s'",
);
}
-
+
}
}
-
-
+
+
advuser_module_invoke('filter', $filters);
/*// Regular filters
$filters = array(
@@ -160,7 +159,7 @@ function advuser_admin_filter_form_submi
function advuser_admin_filter_form() {
//print_r($_SESSION['advuser_user_filter']);
-
+
$sess = &$_SESSION['advuser_user_filter'];
$sess = is_array($sess) ? $sess : array();
$session = $sess;
@@ -169,7 +168,7 @@ function advuser_admin_filter_form() {
$i = 0;
$form['filters'] = array('#type' => 'fieldset', '#title' => t('Show only items where'), '#theme' => 'advuser_filters');
-
+
$types_used = array();
foreach ($session as $filter) {
list($type, $value) = $filter;
@@ -216,13 +215,13 @@ function advuser_admin_users_operations(
'email' => array(t('Email users'), 'advuser_multiple_email_confirm', 'confirm'),
'delete' => array(t('Delete users'), 'advuser_multiple_delete_confirm' , 'confirm')
);
-
+
advuser_module_invoke('actions', $external);
-
+
foreach ($external as $k => $v ) {
$operations['external_'.$k] = $v;
}
-
+
return $operations;
}
@@ -232,13 +231,13 @@ function advuser_admin_user_build_filter
// Build query
$field_where = $where = $where_args = $having_args = array();
$join = '';
-
+
$cnt = 0;
$session = $_SESSION['advuser_user_filter'];
asort($session);
foreach ($session as $filter) {
list($key, $value) = $filter;
-
+
// Check if process the filter an how
$where_key = TRUE ;
$where_keys = array_keys($where, $filters[$key]['where']);
@@ -249,14 +248,14 @@ function advuser_admin_user_build_filter
$where_key = FALSE;
}
}//foreach;
-
+
}
-
+
if ( isset($filters[$key]['where']) && $where_key ) {
$where[] = $filters[$key]['where'];
$where_args[] = $value;
}
-
+
// Check if process the filter an how
$field_where_key = TRUE;
$field_where_keys = array_keys($field_where, $filters[$key]['field_where']);
@@ -267,7 +266,7 @@ function advuser_admin_user_build_filter
$field_where_key = FALSE;
}
}//foreach;
-
+
} else {
if ( isset($filters[$key]['field_where']) ) {
$cnt++;
@@ -278,15 +277,15 @@ function advuser_admin_user_build_filter
$field_where[] = $filters[$key]['field_where'];
$having_args[] = $value;
}
-
+
// Proces join just once
if ( ! strstr($join, $filters[$key]['join'] . ' ') ) {
$join .= $filters[$key]['join'] . ' ';
}
}
-
+
//print_r($field_where);
-
+
// build query smartly
$where_sql = 'WHERE u.uid > 1 AND ';
foreach ( (array) $where as $w ) {
@@ -305,13 +304,13 @@ function advuser_admin_user_build_filter
$where_sql .= ') AND ';
}
$where_sql .= '1';
-
+
$where = count($where) ? 'WHERE u.uid > 1 AND '. implode(' AND ', $where) : '';
$field_where_cnt = count($field_where);
$field_where = $field_where_cnt ? implode(' OR ', $field_where) : '0';
$having[] = 'SUM(IF(' . $field_where . ',1,0)) = ' . $cnt;
$having = count($having) ? 'HAVING '. implode(' AND ', $having) : '';
-
+
$args = array_merge($where_args, $having_args);
return array( 'where' => $where_sql, 'join' => $join, 'args' => $args, 'having'=> $having);
@@ -332,21 +331,21 @@ function advuser_multiple_email_confirm(
} else {
$user_array = array_filter($edit['users']);
}
-
+
foreach ($user_array as $uid => $value) {
$name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
$form['users'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '
', '#suffix' => check_plain($name) ."\n");
}
$form['operation'] = array('#type' => 'hidden', '#value' => 'email');
-
+
*/
$form['mailsubject'] = array(
- '#type' => 'textfield',
+ '#type' => 'textfield',
'#title' => t('Subject'),
'#required' => TRUE,
);
$form['mailbody'] = array(
- '#type' => 'textarea',
+ '#type' => 'textarea',
'#title' => t('Mail body'),
'#required' => TRUE,
);
@@ -388,7 +387,7 @@ function advuser_multiple_delete_confirm
} else {
$user_array = array_filter($edit['users']);
}
-
+
foreach ($user_array as $uid => $value) {
$name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
$form['users'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '', '#suffix' => check_plain($name) ."\n");
@@ -434,13 +433,13 @@ function advuser_multiple_confirm($all,
} else {
$user_array = array_filter($edit['users']);
}
-
+
foreach ($user_array as $uid => $value) {
$name = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $uid));
$form['users'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '', '#suffix' => check_plain($name) ."\n");
}
$form['operation'] = array('#type' => 'hidden', '#value' => $action);
-
+
if ( function_exists($user_func) ) {
$user_func($all, $form);
}
@@ -460,45 +459,45 @@ function advuser_admin_users() {
if ( $op == 'Update all' ) {
$all = TRUE;
}
-
+
foreach (advuser_admin_users_operations() as $key => $value) {
if ( $value[2] == 'confirm' ) {
- if (
+ if (
$_POST['edit']['options_all']['operation'] == $key && $all ||
( $_POST['edit']['options_sel']['operation'] == $key && (count($_POST['edit']['users']) > 0) ) ||
$_POST['edit']['operation'] == $key
) {
-
+
return advuser_multiple_confirm($all, $key, $value[1]);
//return call_user_func($value[1], $all);
//return advuser_multiple_delete_confirm($all);
- }
+ }
}
}
-
+
/*
if (
$_POST['edit']['options_all']['operation'] == 'delete' && $all ||
( $_POST['edit']['options_sel']['operation'] == 'delete' && (count($_POST['edit']['users']) > 0) ) ||
$_POST['edit']['operation'] == 'delete'
) {
-
+
return advuser_multiple_delete_confirm($all);
- }
-
+ }
+
if (
$_POST['edit']['options_all']['operation'] == 'email' & $all ||
( $_POST['edit']['options_sel']['operation'] == 'email' && (count($_POST['edit']['users']) > 0) ) ||
$_POST['edit']['operation'] == 'email'
) {
-
+
if ( $op == 'Update all' ) {
$all = TRUE;
}
return advuser_multiple_email_confirm($all);
}
*/
-
+
$filter = advuser_admin_user_build_filter_query();
$result = pager_query('SELECT u.* FROM {users} u '. $filter['join'] .' LEFT JOIN {profile_values} pv ON u.uid = pv.uid LEFT JOIN {profile_fields} pf on pv.fid = pf.fid '. $filter['where'] .' GROUP BY u.uid ' . $filter['having'] . ' ORDER BY u.login DESC', 50, 0, NULL, $filter['args']);
@@ -514,7 +513,7 @@ function advuser_admin_users() {
}
$form['options_all']['operation'] = array('#type' => 'select', '#options' => $options);
$form['options_all']['submit'] = array('#type' => 'submit', '#value' => t('Update all'));
-
+
$form['options_sel'] = array(
'#type' => 'fieldset', '#title' => t('Update on selected records only'),
'#prefix' => "" , '#suffix' => "
",
@@ -542,7 +541,7 @@ function advuser_admin_users() {
// Call the form first, to allow for the form_values array to be populated.
$output .= drupal_get_form('advuser_admin_users', $form);
-
+
return $output;
}
@@ -681,14 +680,14 @@ function advuser_settings() {
'#description' => t('The subject of the mail that is going to be sent to the user. Placeholder variables: %username, %site.'),
'#default_value' => variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT),
);
-
+
$form['advuser_mailonnew']['advuser_new_mail'] = array(
'#type' => 'textarea',
'#title' => t('Mail body'),
'#description' => t('The mail that is going to be sent to the selected roles. Placeholder variables: %username, %site, %uri.'),
'#default_value' => variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL),
);
-
+
$roles = user_roles(1);
/*$options = array();
foreach ( $roles as $rid => $role) {
@@ -709,7 +708,7 @@ function advuser_settings() {
'#options' => $roles,
'#default_value' => $values /*variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES)*/,
);
-
+
if ( module_exist('profile') ) {
$form['advuser_profile'] = array(
'#type' => 'fieldset',
@@ -723,7 +722,7 @@ function advuser_settings() {
while ( $row = db_fetch_object($result)) {
$fields[$row->fid] = $row->title;
}
-
+
$values = array();
$options = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
foreach ( (array)$options as $opt => $v ) {
@@ -731,32 +730,32 @@ function advuser_settings() {
$values[] = $v;
}
}
-
+
$form['advuser_profile']['advuser_profile_fields'] = array(
'#type' => 'checkboxes',
'#description' => t('Profile fields to be used as filters for the users.'),
'#title' => t('Profile fields'),
'#options' => $fields,
'#default_value' => $values,
- );
-
+ );
+
}
-
+
return $form;
}
function advuser_user_insert($edit, $user, $category) {
// send mail
if ( variable_get('advuser_new_notify', ADVUSER_DEFAULT_NEW_NOTIFY) ) {
-
+
$from = variable_get("site_mail", ini_get("sendmail_from"));
$body = variable_get('advuser_new_mail', ADVUSER_DEFAULT_NEW_MAIL);
$subject = variable_get('advuser_new_subject', ADVUSER_DEFAULT_NEW_SUBJECT);
-
+
$variables = array(
'%username' => $user->name,
- "%site" => variable_get("site_name", "drupal"),
- "%uri" => url('user/'.$user->uid, NULL, NULL, TRUE),
+ "%site" => variable_get("site_name", "drupal"),
+ "%uri" => url('user/'.$user->uid, NULL, NULL, TRUE),
);
$roles = variable_get('advuser_new_roles', ADVUSER_DEFAULT_NEW_ROLES);
@@ -770,7 +769,7 @@ function advuser_user_insert($edit, $use
}
}
}
-
+
$result = db_query('SELECT u.mail, u.name FROM {users} u LEFT JOIN {users_roles} ur on u.uid = ur.uid WHERE 0 ' . $role_where );
while ($row = db_fetch_object($result)) {
$user_subject = strtr($subject, $variables);
@@ -778,19 +777,19 @@ function advuser_user_insert($edit, $use
user_mail($row->mail, $user_subject, $user_body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
}
}
-
+
}
}
-/**
- * hook_user implementation
+/**
+ * hook_user implementation
*/
function advuser_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'insert':
return advuser_user_insert($edit, $user, $category);
}
-
+
//print $type;
}